任务是:
编写一个Python程序,提示用户创建一个用户帐户,并检查所提供的用户名和密码是否合法。在
注意:密码应该以字母开头,并且只能由字母、数字和下划线符号“u”组成。长度应该在8到16之间。在
我遇到了“密码应该以字母开头,并且只包含字母、数字和下划线符号”的问题部分。(我知道这不是最优雅的代码)username=input("Please enter a username:")
usepass=input("Please enter a password:")
#username
if len(username)<6 or len(username)>12:
print("Username is incorrect length. Your username must be between 6 and 12 characters.")
if username.isalnum() == False:
print("Username must only contain letters and numbers.")
username1=username[0]
if username1.isnumeric()== True :
print ("Your username must start with a letter")
#password
if len(usepass)<8 or len(usepass)>16:
print("Password is incorrect length. Your password must be between 8 and 16 characters.")
usepass1=usepass[0]
if usepass1.isalpha()==False:
print("Your password must start with a letter")
if usepass.isalnum()==False:
print("Your password must only contain numbers, letters and underscores.")