145k views
3 votes
Create a Find Smallest app that:

- Allows a user to create a list of at least 5 food items.
- Displays all of the items in the `foods` list using a `for` loop.
- Using a `for` loop, display all of the items in the `foods` list with
less than 7 letters.

1 Answer

6 votes

Answer:

Here is the code:

def main():

foods = []

# Get at least 5 food items from user

print("Enter at least 5 food items:")

while len(foods) < 5:

food = input("Enter a food item: ")

foods.append(food)

# Display all items in the foods list

print("\\All food items:")

for food in foods:

print(food)

# Display food items with less than 7 letters

print("\\Food items with less than 7 letters:")

for food in foods:

if len(food) < 7:

print(food)

if __name__ == "__main__":

main()

Step-by-step explanation:

User Vitalii Dmitriev
by
8.6k points

No related questions found