我有一个数据库程序来保存数据,但我无法解决这个问题:
我有两个函数。当您在程序中输入 名为addy()的函数启动 并要求对变量进行更多输入 然后返回主屏幕, 然后用户可以输入S 哪个节目开始 然后,它应该显示您添加到变量中的内容
问题: 它没有从前面的定义中获取值
代码:
def addy():
os.system('cls')
addel = input('what is the name of the operating system?: \n')
os.system('cls')
time.sleep(1)
print(addel + ' Has been added to the database!')
time.sleep(2)
program()
def show():
print('Heres a list of the operating systems you have added:')
time.sleep(5)
program()
addel = addy()
print(addel) # this should print the value from the previous function
原因有两个
Addel
是局部变量而不是全局变量。因此,您只能在addy
函数中使用它李>函数
addy
没有返回值,因此代码无法工作。 要解决此问题,请编写作为addy函数中的最后一行,它将工作,因为现在函数有一个返回值
相关问题 更多 >
编程相关推荐