0

so this is the code, it goes on forever, but i cant trace why. At some point i should be 10, and then 10<10 should be false and the code should stop. also how does it read the range part. for example is it like while i < 0, 1, 2, 3, etc..??

i = 0
numbers = []
abc = range(0, 10)

def loop(i):
    while i < abc:
        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    

quest = raw_input('> ')    
if quest == 'i':
    loop(i)

print "the numbers: "

for num in numbers:
    print num    
Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
learn123456
  • 177
  • 1
  • 2
  • 9
  • 1
    You are comparing an `int` with a `list`? And `list` are always greater than `int` in Python 2 https://stackoverflow.com/questions/7167657/python-list-greater-than-number – Taku Jul 20 '18 at 01:00
  • This could heplp you solve such miracles the next time 'round: [How to debug small programs (#1)](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) – Patrick Artner Jul 20 '18 at 05:37

1 Answers1

0

You are comparing an integer to a list, which always returns true (list bigger than int) . You might want to use while I < abc[-1]

I Dav
  • 374
  • 1
  • 2
  • 8
  • This would result in `while I < 9:` whereas the op wants `while I < 10:`. Using the final value in the list seems like a bit of an obfuscation. I don't think we even need the while loop, instead for `for i in range(0, 10):`would make the code idiomatic. – Paul Rooney Jul 20 '18 at 01:10