I'm working through learn python the hard way, and in exercise 33 extra credit 2 I'm trying to utilize either raw_input or argv to set a variable that will be used in a while loop:
# from sys import argv
# script, my_num = argv
def all_the_numbers(n):
"""increment by 1 up to limit n"""
i = 0
numbers = []
while i < n:
print "At the top i is %d" % i
numbers.append(i)
i = i + 1
print "Numbers now: ", numbers
print "At the bottom i is %d" % i
# print "Please enter an integer: "
# n = raw_input("#")
# n = my_num
n = 10
all_the_numbers(n)
The hard coded n = 10 works as expected; printing the lines up to 10. But passing in a value as my_num from argv and/or setting the variable from raw_input results in an endless integer incrementation upwards. What is different about the latter two forms of setting variables that they do not behave exactly like the hard coded setting of the same variable?