Python初学者在这里,对不起,如果这是一个简单的问题!
我已经有一个工作while循环了
while True:
do_youwanttoplay = input("Do you want to play? ").lower()
if do_youwanttoplay == "yes":
print ("You are starting with", health, "health")
print ("Let's play!")
break
elif do_youwanttoplay == "no":
print ("Cya...")
break
else:
print ("Please enter either yes or no")
但在下一段代码中,我希望它能检查用户是否输入了“yes”或“no”(它目前正在这样做),并检查用户是否输入了“across”或“around
while True:
first_choice = input("First choice... Left or Right (left/right)? ").lower()
if first_choice == "left":
ans = input("Nice, you follow the path and reach a lake...Do you swim across or go around (across/around)? ")
break
elif first_choice == "right":
print("test")
else:
print ("Please enter either left or right")
if ans == "across":
print ("You managed to get across, but were bit by a fish and lost 5 health")
health -= 5
print ("Your health is now", health)
elif ans == "around":
print ("You went around and avoided getting bit by the fish, well done!")
1条答案
按热度按时间jdzmm42g1#
这是一个如何组织while循环的问题。
我能够得到以下工作,在一种方式,我相信是你想要的。
我添加了一个
stop
布尔值来确定是否应该退出主循环。