yoshyosh yoshyosh - 1 year ago 51
Python Question

Python: Problem with raw_input reading a number

unfortunately raw_input is not doing what I need it to do. What I am trying to do is get totPrimes = whatever I type in at the prompt. If i replace

while count < totPrimes
while count < 50
this script works. If I type 50 into the prompt, this script doesnt work, I'm afraid raw_input isn't the function im looking to use? Here is a snippet of my code:

testNum = 3
div = 2
count = 1
totPrimes = raw_input("Please enter the primes: ")

while count < totPrimes :
while div <= testNum :

Answer Source


totPrimes = int(totPrimes)
while count < totPrimes:
    # code

raw_input gives you a string you must convert to an integer or float before making any numeric comparison.