Python Forum

Full Version: Problem in Loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
num=raw_input("enter range")
def pract(num):
    i=0
    numbers=[]
    while i<=(num):
        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
     for x in numbers:
         print"numbers now:",x

pract(num)
The code is returning an infinte list i dont know whats the problem?help
raw_input returns string. you need to convert it to int/float in order to make comparison with int i in the while condition. Also have a look at range built-in function
Thanks.. working now