我相信这个错误意味着我不能在一个循环中包含一个变量,但是我正在努力寻找解决方法。。。。你知道吗
错误是
TypeError: range() integer end argument expected, got unicode.
这本书想问我的问题是:
Try wring a program the will prompt for an number and print the correct times table (up to 12).
这是我的密码:
def main():
pass
choice = raw_input("Which times table would you like")
print ("This is the", choice , "'s times table to 12")
var1 = choice*12 + 1
for loopCounter in range (0,var1,choice):
print(loopCounter)
if __name__ == '__main__':
main()
有什么建议吗?提前谢谢。你知道吗
raw_input
函数给您一个字符串,不是整数。如果您希望它是一个整数(例如,如果您希望将它乘以12或在range
调用中使用它),则需要如下内容:这种简单化的解决方案存在潜在的问题(例如,当您输入的是而不是一个数字时会发生什么),但这应该足以解决您当前的问题。你知道吗
您的程序将运行一些更改。你知道吗
现在您可能需要对其进行更多的调整,以便获得正确的输出,上面的代码将编译并运行。你知道吗
这个错误仅仅意味着它在假定整数时得到了一个unicode值。 这是因为使用
raw_input
表示choice
。你知道吗编辑:
raw_input
不解释您的输入。input
是的。你知道吗相关问题 更多 >
编程相关推荐