如果用户名不在3到9个字符之间,我尝试不接受它。你知道吗
print (""+winner+", please input your first name, maximum of 10 characters.")
winnername = str(input())
length = (int(len(winnername)))
if 3 > length > 10:
loop5 = 1
while loop5 == 1:
print ("name is too short")
winnername = input()
length = len(winnername)
if (length) <3 and (length) <10:
break
print ("name accept")
如果所提供的输入不符合上述文本中概述的要求,我希望它循环并向用户请求另一个输入。你知道吗
让我来修正你的代码,优雅而干净:
问题是
3 > length > 10
永远不会执行,因为3
永远不会大于>
而10
if 3 > length > 10:
正在检查以确保长度小于3且大于10,这是不可能的。你知道吗因此,检查应该是
if 2 < length < 10:
(对于长度3到9是这样的)关于你的第一句话,据我所知,从代码中你实际上是想让字符的最大数量是10个,而不是9个。你知道吗
下面是一个可能的解决方案,你正在努力实现。下面的脚本将一直询问用户,直到名称长度在允许的范围内。你知道吗
您还可以考虑先对winnername执行一些验证(不允许空格或任何其他特殊字符)。你知道吗
相关问题 更多 >
编程相关推荐