I am trying to get my program to take a user inputted list and use it as an argument for the stringList function but it keeps thinking that the list is just a string. How do I get it to see it as an actual list?
Here is the code that I have so far:
spam = ["apples", "bananas", "tofu", "cats"]
sillyList = []
def stringList(list):
ending = len(list)
try:
print()
for item in list[0: ending - 1]:
print(item, end=", ")
print("and " + list[ending - 1])
except:
print("Error: List contains no items. Do you wish to try again?")
answer = input().lower()
if answer == "yes" or "y":
print()
askListName()
elif answer == "no" or "n":
sys.exit()
def askListName():
print("Enter the list name:")
listName = input()
try:
stringList(listName)
except:
print("Error: Invalid list name.")
askListName()