I'm trying to make a function that will append an item to a list based on user input. Python 2.7.8, Windows 7.
What am I doing wrong?
# Lab 4.1 Create five separate lists. Each list should have a theme and theThe prompts work fine but the output is:
# theme should be reflected in the list name and its elements. Examples are:
# pets = ['dog', 'cat', 'rat']
# numbers= [34, -1232, 456, 2134]
weather = ['Clear','Rain','Snow','Storm','Windy','Hail','Fog']
locations = ['Park','Forest','Beach','River','Library','Cafe','College',
actions = ['Walk','Examine','Activate','Talk','Wait','Eat','Sleep','Read',
day = ['Morning','Mid-day','Afternoon','Evening','Twilight','Night',
animals = ['fish','Crow','Deer','Seagull','Mosquito','Racoon','Skunk',
# Lab 4.2 Using the lists you defined in 4.1, define functions that
# demonstrate your knowleldge of the list functions: append, extend,
# remove, pop, index, sort, and reverse. Write at least 2 examples
# using each function.
# ^This is the start of the generic list selection code.
listName = str(raw_input('You choose to append an item to a list.\nFirst we'
' must select a list.\nType the name of one of these lists to see its'
' elements:\nweather, locations, actions, day, or animals.\n'
'Which list do you want to view? '))
# ^get name of list to append an element
if listName == 'weather' or 'Weather':
for i in weather:
elif listName == 'locations' or 'Locations':
for i in locations:
elif listName == 'actions' or 'Actions':
for i in actions:
elif listName == 'day' or 'Day':
for i in day:
elif listName == 'animals' or 'Animals':
for i in animals:
# ^print all the elements in the selected list
print 'There is no list available under that name!'
# ^print if user mistypes name of list
# ^the generic list selection input code ends in the line just before this comment.
appendElement = raw_input('Please type the element you wish to append to'
' the selected list: ')
# ^get the element user wants to append to list
appendCheck = str(raw_input(appendElement + ' Is this correct, yes or no? '))
if appendCheck == 'yes' or 'Yes':
elif appendCheck == 'no' or 'No':
print 'I\'m sorry, but it seems you mistyped your element. Try again'
# ^check with user to make sure element is correct. pass if t, break if f
appendEleType = str(raw_input('Is the new element a string, float, or'
' integer? Please type the word as it is spelled here and press enter. '))
# ^get element type from user
if appendEleType == 'string':
elif appendEleType == 'float':
elif appendEleType == 'int':
# ^wrap element type with proper conversion function
newList = eval(listName + '.append(' + appendElement + ')'
for i in newList:
What am I doing wrong?