Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Mark Kohner
Mark Kohner
1,121 Points

while True: infinite loop breaks prematurely

I am trying to get numbers from input, print them out, and return the numbers. I am having issues, however, getting the input to 'keep getting asked' while the loop is running. Why is this exiting early, or running but not getting more inputs?

print('Enter some numbers')
def numba():
    while True:
        entered = input('enter numbers and type done to quit')
        if entered == 'done':
            break
        print(num)
print('Done')
numba()

why isn't this saying: Print some numbesr

input for entering numbers

-> returned number

input for entering numbers

-> returned number

input for entering numbers

->done -> break -> ->print 'Done' ?

1 Answer

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

I think you need to enclose your if statement. You need to print before you break also.