Search code examples
pythonloopscountercountdown

Python Count up & Down loop


How can I simply transform this loop to count up from 1 to 100, and display the numbers? I'm starting to code recently. It works fine when counting down, but I can't figure out how to make it go from 1 -100

example:

count = 100
while count > 0 :
    print(count)
    count = count - 1

Solution

  • Start at 1, and change your conditional to break out when you reach 100. Add 1 each loop through.

    count = 1
    while count <= 100:
        print(count)
        count += 1