我应该编写一个验证用户名的程序。用户名必须包含至少8-15个字母,不能包含字母数字值。所以,你只能有数字和字母。开始或结束时不能有数字。而且,您必须至少有一个大小写字母和至少一个数字。我知道如何做所有事情,但如何让程序检查它是否包含任何大写字母。我试图做“如果不在”,但没有运气。这是我迄今为止所拥有的。检查字符串中是否存在大写字母
username = input("please enter a name: ")
for i in username:
while len(username) < 8 or len(username) > 15:
print("Password is too long or too short")
username = input("please enter a name: ")
j = 31
while j < 47:
j += 1
while chr(j) in i:
print("No alphanumeric values allowed.")
username = input("please enter a name: ")
k = 57
while k < 64:
k += 1
while chr(k) in i:
print("No alphanumeric values allowed.")
username = input("please enter a name: ")
l = 47
while l < 57:
l += 1
while chr(l) in username[0]:
print("you cannot have a number in the beggining")
username = input("please enter a name: ")
while chr(l) in username[-1]:
print("you cannot have a number in the end")
username = input("please enter a name: ")
究竟什么是你的问题反驳他们? –
这个早期的帖子应该会帮助你: http://stackoverflow.com/questions/6602111/how-to-search-for-a-capital-letter-within-a-string-and-return-the-list-字词 – nbryans
你为什么使用键码?你知道,显然有更好的方法来做到这一点。 – Laurel