我希望从文件1中获取“得分”变量,并进行进一步处理,但失败了。
我尝试了类似的代码尝试从文件Question.py导入变量“分数”到question2.py,例如在脚本中,全局变量,“从问题导入分数”,而没有全局变量。
文件:-question.py
from MCQ import question
global score
class questionss:
def run_test(questions):
score = 0
for question1 in questions:
answer = input(question1.prompts)
if answer == question1.answer:
score += 1
print("You scored " + str(score) + "/" + str(len(questions)) +
run_test(questions)
File:- question2.py
from question import score
print(str(score))
print(score)