首页 > 解决方案 > 编辑要求用户名的程序。它应该检查前四个字符是字母,第五个和第六个是数字。在 Python 中

问题描述

user = input("Enter your username (It should be of minimum 7 characters): ")
for a in user:
    for a in range(0,4):
        if (a.isalpha()) == True:
            print("The first four character are alphabet !")
        else:
            print("the first four characters are not alphabets !")
            break
for a in user:
    for a in range(4,6):
        if a.isdigit()==True:
            print("The fifth and sixth characters are digits !")
        else:
            print("The fifth and sixth characters are not digits !")
            break

标签: pythonpython-3.6

解决方案


a in user:将遍历每个字符用户,并将其分配给每次。删除你的第二个。那应该行得通。


推荐阅读