Python 2.7 python名称错误
我是python的新手,经常遇到这样的错误: “NameError:未定义名称“prompt” 下面是我正在尝试运行的代码:Python 2.7 python名称错误,python-2.7,Python 2.7,我是python的新手,经常遇到这样的错误: “NameError:未定义名称“prompt” 下面是我正在尝试运行的代码: def accountLogin(prompt): while true: if(os.path.exists("info.csv")): return else: print "Please enter username and password" if len(u
def accountLogin(prompt):
while true:
if(os.path.exists("info.csv")):
return
else:
print "Please enter username and password"
if len(username) < 0:
print "please enter username"
elif len(username) > 0:
println "please enter password"
return
if password = false:
print "please enter password"
elif password = true:
return "info.csv"
def accountLogin(提示):
尽管如此:
如果(os.path.exists(“info.csv”):
返回
其他:
打印“请输入用户名和密码”
如果len(用户名)<0:
打印“请输入用户名”
elif len(用户名)>0:
println“请输入密码”
返回
如果password=false:
打印“请输入密码”
elif password=true:
返回“info.csv”
我知道你想要什么,我和你一样是新手,希望这段代码能对你有所帮助,请投票支持我的答案
def get_formatted_name(username, password):
"""Return a all info, neatly formatted."""
all_info = username + ' ' + password
return all_info.title()
while True:
print("\nPlease tell me your username:")
print("(enter 'q' at any time to quit)")
username = raw_input("Username: ")
if username == 'q':
break
password = raw_input("Password: ")
if password == 'q':
break
formatted_name = get_formatted_name(username, password)
print("\nYour account information is, " + formatted_name + "!")
您可以阅读有关while循环的更多信息
给我你的票,我需要。
谢谢有这么多事情不对,从哪里开始
println
不正确,需要比较,=
,而不是=
-这就是分配…您如何调用accountLogin?@Luke.py accountLogin(原始输入);info.csvdont传递原始输入。。。传递与raw_inputYes关联的变量,它应该是,我在新代码中将它定义为一个字符串,因此它返回一个错误,表示该字符串不可调用。您如何调用它
def accountLogin(username,password):
if len(username) == 0:
username = str(raw_input("please enter username: ")).translate(None, "'").translate(None, '"')
return(username,password)
if len(password) == 0:
password = str(getpass.getpass("please enter password: ")).translate(None, "'").translate(None, '"')
return(username,password)
else:
return(username,password)
loginUsername,loginPassword = accountLogin(loginUsername,loginPassword)