所以我有这个数据验证程序验证了名称,电子邮件和年龄,但它给了我一个错误
def emailcheck():
if (email[0] == "@"):
print("email not valid try again")
email = input("enter email:")
if ("@" not in email):
print("your email is not valid")
email = input("enter email:")
if (email == ""):
print("email is empty")
email = input("enter email:")
def namecheck():
if (name == ""):
print("name is empty")
name = input("enter name:")
def agecheck():
if (age != int):
print("age must be a number")
age = input("enter your age:")
if (age != range(1,120)):
print("i dont even know what to say")
age = input("enter your age:")
while True:
email = input("enter email:")
emailcheck()
name = input("enter name:")
namecheck()
age = input("enter your age:")
agecheck()
发生错误:
追踪(最近一次通话): 文件“python”,第29行,in 在电子邮件检查中输入“python”,第2行 UnboundLocalError:赋值前引用的局部变量'email'
我需要解决这个问题
答案 0 :(得分:0)
将变量作为参数传递给函数,因为它们不会在该范围内定义。例如
def emailcheck(email):