183k views
2 votes
Write a loop that continually asks the user what food the user has in their refrigerator until the user enters apples, in which case the loop ends. It should acknowledge the user in the following format. For the first food, the user might say "hamburger," so your response would be, "You have a hamburger with a total of 1 food(s) if they enter hamburger, and so on until they enter “apples” at which point the loop ends. ---- make sure you save your file as "may28.py" *

1 Answer

3 votes

(Disclaimer: I am not a professional, so it might not be the most concise answer possible, but I did run the Python script and it works)

Answer:

user_input = input("What food do you have in your refrigerator? ").lower()

count = 0

while True:

if user_input != 'apples':

count += 1

print(f'You have a {user_input} with a total of {count} food(s)\\')

user_input = input("What food do you have in your refrigerator? ")

else:

break

User Michael Berk
by
5.6k points