单词的Python数据验证
您好,我在验证时遇到了一个问题,强制用户输入5个单词,目前如果他们输入一个空格,他们也可以输入。这是我的密码:单词的Python数据验证,python,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) 或者可能添加一个is_单词测试,以应用
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)
或者可能添加一个is_单词测试,以应用于使用all的单词,以防您想要拒绝数字或其他内容。这是什么。val?您的代码无效pythonWelcome to StackOverflow,为了得到答案,请阅读并遵循此说明。
words = sentence.split()
if len(words) == 5:
print('good')