但是,我有一个简短的问题,我正在尝试制作一个测验程序。我希望在整个程序中共享函数数据,
那么我该如何让 ask 函数 gen 从 getQuestion 中获取数据呢?
import random
All_questions = ["whats obamas last name ","Riclug is snygg ","Are traps gay "]
questions_Right = ["care","no","no"]
points = 0
tries = 3
ListNumber = len(All_questions)
def getQuestion():
question_number = random.randint(0, ListNumber - 1)
right_anwser = questions_Right[question_number]
Question = All_questions[question_number]
def ask(Question,right_anwser):
print("The question is: ")
anwser = input(Question+": ").casefold()
if anwser == right_anwser:
print("yes,", right_anwser,"was right\n")
All_questions.remove(Question)
questions_Right.remove(right_anwser)
else:
print("Sorry, but the answer was", right_anwser,"\n")
while True:
if ListNumber == 0:
print("Game over")
break
else:
print(ListNumber)
getQuestion()
ask()
print(All_questions)