我已经有一段时间的问题了,我的一些价值观只是拒绝存储。这很可能是因为我在某个地方违反了一条规则,但在互联网上搜索了一段时间后,我找不到问题所在。你知道吗
代码:
#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
变量超出范围。你知道吗您可以将它作为参数传递到
print_mining_values()
函数中,并以这种方式打印它所以
print_mining_values()
会变成:你的
min_count_set()
函数会变成:注意变量现在被传递到打印函数中。你知道吗
可以将
stancount
声明为全局变量,如下所示:您必须在函数外部声明变量,并在函数内部修改它们,因为变量在定义它们的地方是局部的,因为您在函数内部定义
stancount
,当您离开函数时,它基本上被“删除”:我推荐类似的方法这将
stancount
设置为您在函数中设置的值,并允许您在以后打印它相关问题 更多 >
编程相关推荐