单词的Python数据验证

2024-04-20 05:14:20 发布

您现在位置:Python中文网/ 问答频道 /正文

你好,我有一个问题,使我的验证,迫使用户输入5个字,目前如果他们输入一个空间,他们也可以去槽。这是我的密码:

cntr = 0 
for x in range(len(this.val)): 
    if this.val[x]. == ' ' and not this.val[x-1] == ' ' and x != 0: 
        cntr = cntr + 1

if cntr lt 4: 
    error(res.Q3error)

Tags: and用户inlt密码forlenif
1条回答
网友
1楼 · 发布于 2024-04-20 05:14:20
words = sentence.split()
if len(words) == 5:
   print('good')

或者使用all()添加一个“is\u word”测试来应用于“words”,以防拒绝数字或其他内容。你知道吗

相关问题 更多 >