python - 编辑要求用户名的程序。它应该检查前四个字符是字母,第五个和第六个是数字。在 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
解决方案
a in user:
将遍历每个字符用户,并将其分配给每次。删除你的第二个。那应该行得通。
推荐阅读
- javascript - 循环进入 Object 以过滤它有时有效,有时无效 Angular 11
- python - 我想通过终端向python文件提供文件输入,但通过在linux中使用'<'进行路由
- java - @JsonPropertyOrder 名称独立于属性命名策略
- android - 在我的底部文本变小的蓝牙热敏打印机中打印
- laravel - laravel 8 基于字符串动态创建Class对象
- split - 基于 Hypen 的分词
- php - make:entity command: [ERROR] make:entity 只支持注解映射
- dart - null 和 ()=>null 有什么区别?
- swiftui - 当父视图更新时,SwiftUI 中的工作表冻结
- mysql - MySQL 在 JOIN 中使用 SUM?