我已经开始在学校学习 Python 大约一个月了,我决定做一个测验。我已经添加了一个评分系统,因此如果您错误地回答了一个问题,它会告诉您您的分数。但是,这是行不通的,它总是会给你一个 0 分。另外,如果他们没有通过一个问题,有没有办法只写一个 else 语句,而不是每个问题一个?谢谢 :)
这是代码示例(Python 3.2.3):
#QUIZ
print("Welcome to the quiz")
print("Please choose a difficulty:")
difficulty = input("A) Hard B)Easy")
if difficulty == "A":
score = 0
print("")
def question(score):
print("You chose the hard difficulty")
print("Where is the Great Victoria lake located?")
answer1 = input("A) Canada B)West Africa C)Australia D)North America")
if answer1 == "C":
print("Correct")
score = score+1
else:
print("you failed the quiz")
print("Score:",score)
quit()
def question2(score):
print("Who is most responsible for cracking the Enigma Code")
answer2 = input("A) Alan Turing B) Jeff Bezos C) George Boole D) Charles Babbage")
if answer2 == "A":
print("Correct")
score = score+1
else:
print("you failed the quiz")
print("Score:",score)
quit()
def diff_easy(difficulty):
if difficulty == "B":
score2 = 0
print("")
def question4(score2):
print("You chose the easy difficulty")
print("What is the capital of Australia?")
answer1 = input("A) Canberra B) Sydney C)Melbourne")
if answer1 == "A":
print("Correct")
score2 = score2+1
else:
print("you failed the quiz")
print("Score:",score2)
quit()
def question5(score2):
print("When was the Great Fire of London?")
answer2 = input("A) 1666 B) 1555 C)1605")
if answer2 == "A":
print("Correct")
score2 = score2+1
else:
print("you failed the quiz")
print("Score:",score2)
quit()
if difficulty == "A":
question(score)
question2(score)
if difficulty == "B":
diff_easy(difficulty)
question4(score2)
question5(score2)