我刚刚参加了计算机科学的入门课程,我们正在研究python。我们只需要为一些练习做一个简单的游戏。我的问题是,当玩家达到$ 0时,我希望我的while循环结束,程序退出。我的程序只是继续从$ 0减去5美元。我需要帮助!!!
print ("Welcome to this game!")
password = input ("please put in $50 for 10 tries to play the game,"\
"then type ok.")
while password != ("ok"):
password = input ("Sorry, wrong password. Please put in $50 for 10 tries to play the game,"\
"then type ok.")
if password== ("ok"):
print ("Time to play")
import random
answer=random.randrange(50)+1
total=50
tries=1
guess=int(input("Guess the number and win $100: "))
while guess !=answer:
print ("you loose $5")
if guess < answer:
print ("too low, you now have", total-5, "dollars left.")
elif guess > answer:
print ("too high, you now have", total-5, "dollars left.")
guess=int(input("Guess the number and win $100: "))
tries=tries+1
total=total-5
print ("well done, you have won $100 in", tries,"tries")