I have to be missing something obvious here right? I ran test on all the variables and everything looked like it was correct when i > val the loop kept running. Any suggestions? Thanks

x = raw_input(":")

def whileloop(val):
    i = 0
    numbers = []

    while i < val:
        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 "The numbers: "

        for num in numbers:
            print num

whileloop(x)

val is a string and it is always greater than integer value i, because the name 'int' is before in alphabet compared to 'str'. So loop never terminates.

Since you are using a loop with a defined limit, a for loop would be better.

how would I go about making it an int? I thought python was not type specific? Bare with me, very new to python. Thank you

thank you casted to int as below and script ran

x = raw_input(":")

def whileloop(val):
    i = 0
    numbers = []

    while i < int(val):
        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 "The numbers: "

        for num in numbers:
            print num

whileloop(x)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.