Small Program in Python: Creating a list
I am so intrigue on how much I know from last year in Python. I have signed up to take a class via Pluralsight which has 11 modules for Python. The more you do and practice the better it gets. This time I wanted to talk about a small program I created. This program basically asks for the user input five times and appends the input to the list that is created. Let’s begin:
#Create an empty list. In this case I called it my_places
my_places = []
#I created a for loop and used a range as I wanted to only have five favorite places notated.
for i in range(5):
#I created a user input and asking the user to name five places they would like to visit
places = raw_input("What are five places you would like to visit?")
#After getting five of their favorite inputs, I used the empty list and append to the places the user put in.
my_places.append(places)
#The list of the five places are printed out
print “My five favorite places to visit are: “, my_places
The final code will look like this:
my_places = []
for i in range(5):
places = raw_input("What are five places you would like to visit?")
my_places.append(places)
print my_places










