I am a relatively new programmer and I can not figure out how to make variables for certain elements in a list. I am trying to do this so I can ask for a certain number and then the console will print a certain element of the list. This is a something I have to do for practice before I can move on to the next level of python. This programming is done through a site called codesters.
Here are the directions I was given to make this program:
- There is a list of 5 foods (use any name).
- Print to the console each food by using an index variable to access each element in the list. (HINT: For loop)
- Ask the user for a food number (location in the list), then print out that food. (E.g. The list are A, B, C, D, E and food number 1 is A)
And this is the code I have so far:
mylist = ["cherry","cake", "rice", "bannana", "strawberry"]
for x in mylist:
print(x)
mylist.append(input("Please enter a food number:"))
Thanks for any help.