def main():
tests = get_initial_input(tests)
assignments = get_initial_input(assignments)
exercises = get_initial_input(exercises)
labs = get_initial_input(labs)
finals = get_initial_input(finals)
print(tests, assignments, labs)
def get_initial_input(x):
val = int(input("How many", x , "were there? "))
return val
main()
我不斷收到錯誤之前引用:局部變量「X」分配
UnboundLocalError: local variable 'tests' referenced before assignment
我已經嘗試了很多不同的東西,試圖讓測試去get_initial_input()
,但它說,它被引用在分配之前。
當我試圖定義它的第一行代碼時,這怎麼可能?
是的,但當您調用'get_initial_input(tests)'時,'tests'不存在。你期望它打印什麼? – Doorknob
你從來沒有在變量'tests = get_initial_answer(tests)'後面定義變量'tests',所以'test'在執行該行時是未定義的。 – ppperry
另外,就像一個附註,我認爲'get_initial_input(tests)',你的意思是'get_initial_input(「tests」)'和val = int(input(「有多少」,x,「那裏? ))'as'val = int(input(「有多少」+ x +「在那裏?」))'修改後的工作代碼:https://repl.it/B0Ex –