在使用函数append将帐户添加到映射时,我遇到了问题。
mapp = ["example"]
example1 = raw_input("Enter Username: ")
if example1 in mapp:
print "yay"
else:
print ("Forgot Username eh?")
example = raw_input("Enter New Username: ")
if example not in mapp:
mapp.append(sana)所以你可以从脚本中看到,如果我输入用户名"example",程序会打印"yay“。如果我输入错误,我可以创建新的“帐户”,当我希望我的程序下次打印"yay“时可以使用它。但当我尝试添加新的“帐户”时,它不起作用。我没有收到任何错误消息或任何东西,但它只是没有添加新的“帐户”到mapp。有什么好主意吗?
发布于 2013-01-28 23:13:57
您没有将正确的变量附加到mapp;您附加的是sana,但您应该附加example:
if example not in mapp:
mapp.append(example)对于此用例,您可以使用set:
mapp = {'example'}
# ...
if example1 in mapp:
# ...
else:
# ...
example = raw_input("Enter New Username: ")
mapp.add(example)https://stackoverflow.com/questions/14564965
复制相似问题