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 Python Basics (2015) Number Game App Number Game Refinement

Is he using recursion?

In the code, the function game() is being called from within itself. This is recursion. It could have been done without recursion as well. Why didn't Kenneth mention this point in the video?

2 Answers

Andrey Misikhin
Andrey Misikhin
16,529 Points

I think you did not pay attention, that Kenneth calls function "game()" not from the body of itself. Pay attention to the indentation.

The following is the call to game() -

if play_again.lower() != 'n':
     game()
else:
     print("Bye!")

This is clearly being executed within the function game(). The indentation shows it. The call is, therefore, recursive.

Andrey Misikhin
Andrey Misikhin
16,529 Points

Yes, you are right! But if you are already knew what the recursion is, that not a problem:) The use of recursion in this case is quite understandable, but there is no one right way to solve the problem. If you see other solutions, then this is very good!