错误的更新代码,现在可以成功检查输入以及最大和最小值错误的更新代码,现在可以成功检查输入以及最大和最小值错误的更新代码,现在可以成功检查输入内容以及最大值和最小值
print("------------------------------------------------------------------------")
print('''Welcome to password Locker, a place where you can
store all your passwords to easily enter your precious accounts without
hassle.''')
print("------------------------------------------------------------------------")
print('''First lets make an account,''')
while True:
first_name = input('''What is your first name?''')
if first_name.isdigit(): #isdi
print("No numbers")
else:
print("Eligible")
break
while True:
sur_name = input('''What is your surname?''')
if sur_name.isdigit(): #isdi
print("No numbers")
else:
print("Eligible")
break
print('''----------------------------------''')
print('''Welcome, {} {}
what would you like your username to be, it should be something
memorable and no longer than ten characters long'''.format(first_name, sur_name))
while True:
username = input("")
if 0 < len(username) < 10:
print('''Nice, username''')
break
elif not username:
pass
else:
print('''Your username should be a maximum of 10 charecters''')
while True:
locker_password = input('''Now it's time to setup a password for your locker: ''')
if len(locker_password) > 4 and len(locker_password) < 11:
print('''{}, is locked in thanks for joining Password Locker'''.format(locker_password))
else:
print("It should be between 4 and 10 charecters long!")```
[1]: https://i.stack.imgur.com/4JnoH.png
答案 0 :(得分:0)
添加一个条件并elif
,然后稍微修改if
条件:
username = input('''Welcome, {} {}
what would you like your username to be, it should be something
memorable and no longer than ten characters long
'''.format(first_name, sur_name))
while True:
username = input()
if 0 < len(username) < 10:
print('''Nice, username''')
break
elif not username:
pass
else:
print('''Your username should be a maximum of 10 charecters''')
示例输出:
Welcome, Bob Smith
what would you like your username to be, it should be something
memorable and no longer than ten characters long
Welcome, Bob Smith
what would you like your username to be, it should be something
memorable and no longer than ten characters long
12133254827258426763589
Your username should be a maximum of 10 charecters
Welcome, Bob Smith
what would you like your username to be, it should be something
memorable and no longer than ten characters long
abc
Nice, username