我有這個問題一段時間,其中我的一些價值觀只會拒絕存儲。這很可能是因爲我打破了某個地方的規則,但是在搜索了互聯網後相當於而且我找不到問題。價值將不會存儲
代碼:
#TO SET#
def min_count_set():
stancount = int(input("How many standard miners do you wish to start with? "))
if (stancount > 10000 or stancount < 0):
print("\n Please enter a valid number to start with. \n \n")
min_count_set()
else:
advcount= int(input("How many advanced miners do you wish to start with? "))
if (advcount > 10000 or advcount < 0):
print("\n Please enter a valid number to start with. \n \n")
min_count_set()
else:
ultrcount = int(input("How many ultra miners do you wish to start with? "))
if (ultrcount > 10000 or ultrcount < 0):
print("\n Please enter a valid number to start with. \n \n")
min_count_set()
else:
print("\n Returning you to the setup menu \n \n")
set_mining_values()
#TO PRINT#
def view_mining_values():
print("\n Printing all of the variables now.")
print("\n Number of standard miners starting with: ")
print(stancount)
print("\n Number of advanced miners starting with: ")
print(advcount)
print("\n Number of ultra miners starting with: ")
print(ultrcount)
我收到的錯誤是:
NameError: name 'stancount' is not defined
我曾試圖給變量stancount
一個數字,然後通過輸入運行它,但當時它只是中繼我輸入前輸入的數字。
你想在功能範圍外訪問stancount變量 –
很多東西都不好,首先你不會在函數中返回任何東西,也不會從遞歸調用中捕獲它,'advcount'和'ultrcount'不會在t他呼叫,每個呼叫是一個完全獨立的範圍 – Netwave
這些變量是在另一個函數中定義的,也向我們展示了set_mining_values的定義 – Saksow