在这里,我试图从用户那里得到一个输入,这个输入被添加到一个列表中,然后在我通过另一个函数运行它之前,必须对该列表进行验证。我知道我需要改变一些东西来比较:只能与整数一起使用,并且列表中的输入将是一个字符串。还有一个错误,它说“无序类型:str()>;int()。我该怎么办?在
def strInput():
string = []
string = str(input("Please enter numbers from 1-999... "))
if validate(string):
return string
else:
strInput()
def validate(i):
if i > 0 and i <= 999:
return True
else:
strInput()
我想收集一份名单给你。下面的代码就可以做到了
应该是:要么这样做:
如果在python3中,
^{pr2}$input
将输入作为字符串或者这样做:
我希望有帮助
打印出来
^{pr2}$相关问题 更多 >
编程相关推荐