我正在做一项任务,我必须进行测验。到目前为止,这是我的代码。
print("Hello and welcome to Shahaad's quiz!") #Introduction
name = input("What is your name? ")
print("Alright", name,", these will be today's topics:") #Topics
print("a) Video Games")
print("b) Soccer")
print("c) Geography")
choice = input("Which topic would you like to begin with?")
if choice == 'video games' or choice == 'Video Games' or choice == 'Video games' or choice == 'a)' or choice == 'a':
print("You picked Video Games.")
print("Question number one:") #Question one
print("What is the most popular FPS (First Person Shooter) game?")
print("a) Call of Duty")
print("b) Battlefield")
print("c) Grand Theft Auto 5")
print("d) Counter Strike")
maxGuesses = 2 #Max number of attempts for the problem
guessesTaken = 0
points = 0
question = input("Your answer: ")
if question == 'Call of duty' or question == 'call of duty' or question == 'Call Of Duty' or question == 'Call of Duty' or question == 'a' or question == 'a)':
print("You are correct! You guessed the question on the first try!")
points = points + maxGuesses-guessesTaken
print("You scored",(maxGuesses-guessesTaken), "points!")
else:
print("Incorrect!")
print("You have", (maxGuesses-guessesTaken-1), "guesses remaining!")
answerb = input("Your answer: ")
if answerb == 'Call of duty' or answerb == 'call of duty' or answerb == 'Call Of Duty' or answerb == 'Call of Duty' or answerb == 'a' or answerb == 'a)':
print("You are correct!")
points = points + maxGuesses-guessesTaken
print("You scored", (maxGuesses-guessesTaken-1), "points!")
我遇到的问题在第 28 行,它说未定义 answerb 但我确实定义了它。我应该用我学过的术语来做这个测验,而且我不允许使用我没有学过的术语,比如 while。我把 else: print wrong 并把 answerb == input 给用户第二次回答的机会。如果他们第一次尝试就得到它,他们不需要为 answerb 插入一些东西。