【发布时间】:2017-10-10 13:34:09
【问题描述】:
我做了一个ATM功能程序,我需要帮助,因为我无法在我的程序中显示我的用户名(un)和密码(pw),错误是
NameError: name 'un' is not defined
我尝试在第一行定义 un ,但用户输入信息后该值没有改变。
#functions
def FWelcome():
print("WELCOME!")
print("Please Log-In to access ATM:")
return;
def FUsername():
while True:
un=input("\nEnter Username ( use only letters ):")
if un.isalpha():
break
else : #invalid
print ("Invalid Username. Use of symbols and/or numbers are not allowed.\n")
return;
def FPassword():
while True:
pw=input("Enter Password ( use only numbers ):")
if pw.isnumeric():
break
else : #invalid
print ("Invalid Password. Use of symbols and/or letters are not allowed.\n")
return;
#atm program
FWelcome()
#username
FUsername()
#password
FPassword()
print("\nHello! Your Username is ", un, " and your password is ",pw )
【问题讨论】:
-
您需要
returnun和pw的值才能在您的函数之外使用它们。