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!