eat a donut in python

To "eat a donut" in Python, we will use input() function to get user input to confirm if the donut is to be eaten. We will then use a loop to simulate the act of taking bites until the donut is completely eaten.

main.py
# Prompting the user to confirm if they want to eat the donut
confirm = input("Do you want to eat the donut? (yes/no): ")

# Checking if user confirms to eat the donut
if confirm == "yes":
  bites = 0
  # Eating the donut
  while bites < 10:
    print("You have taken a bite!")
    bites += 1
  print("Donut eaten!")
else:
  print("Oh well, time to find someone else to eat the donut.")
387 chars
14 lines

In the code above, the user is prompted to confirm if they want to eat the donut using the input() function. If the user types "yes", the while loop simulates them taking bites until the donut is completely eaten (after 10 bites). If they don't confirm, the program ends without eating the donut.

gistlibby LogSnag