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

Question: Number Game Refinement

I've got a question about the code shown in the Number Game Refinement video of Python Basics. Here's the setup: So, Kenneth (an awesome teacher, by the way) builds a function called game(). Inside the game() function, he calls the game() function again to keep playing (if the user doesn't type "n").

So, we're writing a function that actually calls itself... does that work? Is that good program design?

Just confused, Thanks! D.

1 Answer

This is called recursion, and it's very useful in a lot of situations. For this particular program, it would probably be better to use a while loop to check while the response is not "n".

Ohhhhh, ok... Thanks James!