一旦玩家有三个错误的问题,我的游戏继续而不是停止,我该添加/更改什么,使程序停止,一旦三个问题回答不正确。我在程序中包含了一个while循环,我是否做得不好?你知道吗
print ("Note: you must answer using A, B, C or D")
print (" ")
lives = 3
print ("lives =", lives)
print (" ")
name = input ("What is your name?")
print ("Hello",name,". Good Luck.")
while lives != 0:
##is the player ready to start
play = input ("Would you like to start? (Type Y for yes and N for no)")
if play == "Y" or play == "y":
from time import sleep
sleep (1.0)
print("Starting in...")
sleep (1.0)
print("3")
sleep(1.0)
print("2")
sleep(1.0)
print("1")
break
##3, 2, 1 countdown added wk.4 friday
elif play == "N" or play == "n":
print ("End")
break
else:
print ("That is not an answer.\n")
## 1st Question
question1 = ("1. What is Brisbanes AFL team called?")
options1 = (" a. Brisbane Tigers \n b. Brisbane Lions \n c. Brisbane Broncos \n d. Brisbane Magpies")
print (question1)
print (options1)
answer = input (">")
if answer == "B" or answer == "b":
print ("Correct!")
else:
print("Incorrect.")
print ("lives =", lives - 1)
lives=lives-1
## 2nd Question
question2 = ("2. What sport did Greg Inglis play")
options2 = (" a. rugby league \n b. rugby union \n c. AFL \n d. Soccer")
print (question2)
print (options2)
answer = input (">")
if answer == "A" or answer == "a":
print ("Correct!")
else:
print("Incorrect.")
print ("lives =", lives - 1)
lives=lives-1
## 3rd Question
question3 = ("3. Where were the 2018 Commonwealth Games held?")
options3 = (" a. Sunshine Coast \n b. Melbourne \n c. Brsbane\n d. Gold coast")
print (question3)
print (options3)
answer = input (">")
if answer == "D" or answer == "d":
print ("Correct!")
else:
print("Incorrect.")
print ("lives =", lives - 1)
lives=lives-1
## 4th Question
question4 = ("4. How many players in a netball team can shoot?")
options4 = (" a. 1 \n b. 2 \n c. 3\n d. 4")
print (question4)
print (options4)
answer = input (">")
if answer == "B" or answer == "b":
print ("Correct!")
else:
print("Incorrect.")
print ("lives =", lives - 1)
lives=lives-1
当3个问题回答错误而不是停止时,游戏继续。我的测验包含20个问题,但是我附上了4个,这样你就能更好地理解这个问题。非常感谢你的帮助。你知道吗
下面是一个完整的工作代码:
我把你的问题和答案保存在一个列表中,就像你只是在列表上迭代,你不必为每个问题重复代码(打印和生命检查)。你知道吗
如果你还有任何问题,不要犹豫!你知道吗
相关问题 更多 >
编程相关推荐