我的问题是我有多个高清报表登录注册骰子。和IM试图调用从登记表骰子声明一个变量,但它说当它的用户名没有定义。
def register():# registers users
myfile = open ('User names.csv','a+')
print('\n~~Registration~~\n\n')
username = input('Enter your username\n')
password = input('Enter your password\n')
new_data = username+','+password
myfile.write (str(new_data))
def dice():
player_1_username = username
它说名“用户名”没有定义
变量名可以被限制只能注册功能,而不是function.You必须通过用户名来切割功能作为一个参数或使用户名必须是全球性的功能外,以访问骰子中访问。
我想你应该让你的“用户名”变量全球。
global username
username = input()
那么试试这个:
def register():# registers users
myfile = open ('User names.csv','a+')
print('\n~~Registration~~\n\n')
username = input('Enter your username\n')
password = input('Enter your password\n')
new_data = username+','+password
myfile.write (str(new_data))
return username
def dice():
player_1_username = register()
dice() #you must call the function too