我想在这里
一个学生来登记他的账户,他的名字是萨米,他的年龄是16岁我想自动编程,他会选择他的前3个他的名字然后他的年龄创建帐户后,他的用户名不应该是Sammy,应该是 sam16 前3个字母,然后是年龄。
请帮忙
前3封信 Jhonny
他的年龄 12
最后看 jho12
def register():
while True:
username = input("New username: ")
if not len(username) > 1:
print("Username should be more than 2 characters")
continue
else:
break
print("")
while True:
password = input("New password: ")
if not len(password) > 3:
print("Password should be more than 5 characters, " + username )
continue
else:
break
print("")
while True:
age = input("Enter Your age: ")
if not len(age) > 0:
print("Age can't be blank, " + username )
continue
else:
break
print("")
print("Creating account...")
users[username] = {}
users[username]["password"] = password
users[username]["group"] = "user"
time.sleep(2)
print("")
print("Account has been created, " + username)
答案 0 :(得分:1)
username = username[:3].lower()+str(age)
答案 1 :(得分:0)
示例:
name = 'John Soe'
age = 32
username = name[:3] + str(age)
print(username)
输出:
Joh32
在你的情况下你可以这样:
def register():
while True:
username = input("New username: ")
if not len(username) > 1:
print("Username should be more than 2 characters")
continue
else:
break
print("")
while True:
password = input("New password: ")
if not len(password) > 3:
print("Password should be more than 5 characters, " + username )
continue
else:
break
print("")
while True:
age = input("Enter Your age: ")
if not len(age) > 0:
print("Age can't be blank, " + username )
continue
else:
break
print("")
print("Creating account...")
username = username[:3] + str(age)
users[username] = {}
users[username]["password"] = password
users[username]["group"] = "user"
time.sleep(2)
print("")
print("Account has been created, " + username)