3 回答

TA贡献1805条经验 获得超10个赞
更改
vote = input('Enter the name of the player you wish to vote for')
至
vote = int(input('Enter the name of the player you wish to vote for'))
您将从控制台获取输入作为字符串,因此必须将输入字符串转换为int对象才能进行数字运算。

TA贡献1829条经验 获得超7个赞
如果您使用的是Python3.x,input则会返回一个字符串,因此您应使用int方法将字符串转换为整数。
Python3输入
如果存在提示参数,则将其写入到标准输出中,而无需尾随换行符。然后,该函数从输入中读取一行, 将其转换为字符串(将尾随换行符分隔),然后将其返回。读取EOF时,将引发EOFError。
顺便说一句,try catch如果要将字符串转换为int ,这是一种好方法:
try:
i = int(s)
except ValueError as err:
pass
希望这可以帮助。

TA贡献1828条经验 获得超3个赞
默认情况下,input()采用字符串形式的输入。
if (0<= vote <=24):
投票需要输入字符串(假设为“ 4”,“ 5”等),因此无法比拟。
正确的方法是:vote = int(input("Enter your message")将输入转换为整数(根据输入将“ 4”转换为4或将“ 5”转换为5)
添加回答
举报