Python Forum
Problem in Loop - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Problem in Loop (/thread-2022.html)



Problem in Loop - saumya - Feb-11-2017

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


RE: Problem in Loop - buran - Feb-11-2017

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


RE: Problem in Loop - saumya - Feb-11-2017

Thanks.. working now