什么是做这个系统的好方法:
用户最多有 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 分。