38讲习题动动手0改进
user = input("请输入用户名:")password = input("请输入密码:")
initialuserpassword = {"小甲鱼":"I_love_FishC","不二如是":"FishC5201314"}
while user in initialuserpassword:
user = input("请重新输入用户名:")
initialuserpassword = password
break
print("目前已注册的用户名是:",initialuserpassword)
又改进了一下,不知道还有什么地方不妥
密码应该放在输入用户名之后,break 多加了,去掉。最后只打印一个人账户了,应该打印整个字典的账户 加个 for 循环。
另外你自己注册的账户只有在错误时添加到字典,而若没输入错误就没天骄到字典了
应该将字典赋值放置 while 循环外部,参考代码:
user = input("请输入用户名:")
initialuserpassword = {"小甲鱼":"I_love_FishC","不二如是":"FishC5201314"}
while user in initialuserpassword:
user = input("请重新输入用户名:")
password = input("请输入密码:")
initialuserpassword = password
print("目前已注册的用户名是:")
for i in initialuserpassword:
print(i)
user = input("请输入用户名:")
initialuserpassword = {"小甲鱼":"I_love_FishC","不二如是":"FishC5201314"}
while user in initialuserpassword:
print("改用户名已被注册!!!")
user = input("请重新输入用户名:")
password = input("请输入密码:")
initialuserpassword = password
print("-------------\n目前已注册的用户名是:")
for each in initialuserpassword:
print(each)
改过的,哈哈
页:
[1]