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
Siddharth Pande
9,046 Pointsreturn in python
please explain to me in the code below:
def get_guess(bad_guess, good_guess):
while True:
guess = input("enter your guess. > ")
if ..................
elif...............
elif...................
else:
return guess
does the "return guess" breaks the loop?
1 Answer
William Li
Courses Plus Student 26,868 Pointsdoes the "return guess" breaks the loop?
Yes. By design, while True loop is going to keep running until it hits a return statement; break keyword can be used to terminate the loop as well.
Another thing I should point out is that, when writing python code, we don't mix 8 spaces & 6 spaces indentation together; you should indent the python code using 4 spaces throughout.
Siddharth Pande
9,046 PointsSiddharth Pande
9,046 Pointsthanks for you answer @William Li