我應該編寫一個驗證用戶名的程序。用戶名必須包含至少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