不幸的是,raw_input没有按照我的需要去做。我想要做的是得到totPrimes =无论我在提示中输入什么。如果我将while count < totPrimes
替换为while count < 50
此脚本有效。如果我在提示符中键入50,这个脚本不起作用,我害怕raw_input不是我想要使用的函数吗?这里是我的代码片段:Python:raw_input读取数字时出现问题
testNum = 3
div = 2
count = 1
totPrimes = raw_input("Please enter the primes: ")
while count < totPrimes :
while div <= testNum :
考虑将标题更改为更充分的标题。 p.e.'problem with raw_input reading a number',或类似的问题。 – joaquin 2011-04-23 07:52:27
仅供参考,这是Python 2.x中的一个问题,因为您可以比较不同类型的对象。在Python 3.x中它会引发一个'TypeError:unorderable types'。 – katrielalex 2011-04-23 08:57:03