做这个系统的好方法是:
用户最多有2次机会回答问题。 总共有4个问题。 如果用户第一次猜到答案,得2分。 如果用户第二次猜到答案,得1分。 如果用户在2次机会内没有得到答案,则该问题得0分,然后继续下一个问题。 在所有四个问题之后,它列出了他们得到的分数/8。(4题,每题2分)
我试过了:
print("Question number one:") #Question two
print("How many Call of Duty games are there?")
print("a) 4")
print("b) 6")
print("c) 2")
print("d) 8")
question = int(input("Your answer: "))
maxGuesses = 2
guessesTaken = 0
points = 0
if question == 8:
print("You are correct! You guessed the answer on the first try!")
points = points + maxGuesses-guessesTaken
print("You scored", (maxGuesses-guessesTaken), "points!")
else:
print("Incorrect!")
print("You have", (maxGuesses-guessesTaken-1), "guess remaining!")
answer = int(input("Your answer: "))
if answer == 8:
print("You are correct!")
points = points + maxGuesses-guessesTaken
print("You scored", (maxGuesses-guessesTaken-1), "points!")
else:
print("Incorrect!")
print("Next question!")
但这行不通,因为如果用户第一次猜错了答案,第二次猜对了,它仍将被算作2分。在
你需要在他们猜测之后通过做
guessesTaken = guessesTaken + 1
来增加guessesTaken
,或者用一种更短的方法来做guessesTaken += 1
。希望有帮助。在相关问题 更多 >
编程相关推荐