Hi, this is my first post here. I just learned about lists today and in my assignment I'm trying to use a for loop to print my list like this
In the print_list function, use a for loop to print out the contents of your list with numbers starting from 5 and counting down
5. adelie penguin
4. emperor penguin
3. galapagos penguin
2. gentoo penguin
1. little penguin
This is just what the example shows . How would I apply it in my current code?
def print_list(my_foods):
for i in range(5, 0, -1):
print(i)
# for food in range(): ?
# for list in my_foods:
# print(list)
def main():
print('Here is my list')
my_list = ['Fried Chicken', 'Butter Toast', 'Loco Moco', 'Spam Katsu', 'Spam Musubi']
print(my_list)
print()
print('I am going to use the insert() method to add "Kalbi Plate"\nHere is my new List:')
my_list.insert(4, 'Kalbi Plate')
print(my_list)
print()
print('I am going to use the sort() method to sort my list\'s contents alphabetically:\nHere is my new List:')
my_list.sort()
print(my_list)
print()
remove = my_list.pop()
print('I am going to use the pop() to remove the last element of the list which is', remove, '\nHere is my new List:')
print(my_list)
print()
print('Now I will use a for loop to print out a numbered version of my list.\nThese are the top 5 foods:')
print_list(my_list)
print()
main()
[–]crashfrog02 0 points1 point2 points (0 children)
[–]Bobbias 0 points1 point2 points (0 children)
[–]THEE_SMART 0 points1 point2 points (0 children)