def life():
print("You wake up")
eat = input("are you hungry? Please Enter y or n.")
if eat.upper() == "Y":
print("I predict you will eat breakfast")
elif eat.upper() == "N":
print("I predict you will skip breakfast")
while eat.upper() not in ("Y","N"):
print("input not accepted")
eat = input("are you hungry? Please Enter y or n.")
if eat.upper() == "Y":
print("I predict you will eat breakfast")
elif eat.upper() == "N":
print("I predict you will skip breakfast")
print("You leave the house")
day = input("is it cloudy? please enter y or n")
life()
我觉得没有必要在while语句中重复多行代码。有没有办法使 while 语句转到上一行代码并从那里运行它,而不是将相同的代码重新输入回 while 语句。代码似乎运行良好,但我希望它尽可能不那么笨拙。谢谢!
白猪掌柜的
相关分类