I’m trying out Python, and, in my very tired state, can’t seem to find the problem with the code below:
import sys
def printNum(x):
y = 0
while y < x:
print "Number: ", y
y = y + 1
printNum(sys.argv[1])
So, I’m trying to get it to print out y x times. x is passed as a parameter. The loop never ends and I don’t know why!
Currently this code will paste a
strintoprintNum, butprintNumtreats the input (x) like anint. To fix this, convert the input to anint: