【发布时间】:2013-12-27 03:42:03
【问题描述】:
...
elif error.lower() == 'create':
while True:
try:
username = raw_input('What would you like your username to be? ')
username2 = raw_input('Please enter the same username again: ')
while not pickle.load(open("%s.p"%username, "rb"))[1]:
break
break
else:
pickle.load(open("","rb"))
except IOError:
print 'The username is not available. Please try a different one.'
pword = getpass('What would you like your password to be? ')
pword2 = getpass('Please enter the same password again: ')
while pword != pword2:
print 'The passwords do not match.'
pword = getpass('What would you like your password to be? ')
pword2 = getpass('Please enter the same password again: ')
money_left = 0
isguest = False
print 'Your username is %s, and your password is %s. You have $%d ingame money.' % (username, pword, money_left)
...
当我尝试在我的 while True 中创建帐户时,我会在注册之前确保用户名可用。如果用户名不可用,它会再次询问我,但即使是,它仍然会继续询问。你能帮帮我吗?
【问题讨论】:
-
你只是跳出
while not pickle.load循环,你永远不会跳出while True:。 -
如果您认为第二个
break会这样做,那您就错了。它永远不会被执行,因为第一次中断会导致内部循环中的所有代码停止。
标签: python-2.7 while-loop pickle break