This week in 6.00.1x focused on two lectures that introduced the ideas of recursion and objects in programming. In the case of recursion, a number of finger exercises quizzed our ability to understand the way a function can iteratively call upon itself, given some base case it approaches. While the standard “for” and “while” loops we learned in the previous two weeks may seem more intuitive and straightforward, a demonstration of recursion quickly proved its power through a programmatic solution to the classic Tower of Hanoi puzzle game.
One key nugget of information this week was the introduction of lists, which was important because the elements in lists are mutable, or, can permanently be changed in some way, unlike the case with something like strings. We were challenged to put this functionality to the test with this week’s problem set: creating a working, user-interactive version of the word game, Hangman.
Pset3 required us to write 3 key functions that were crucial in implementing the game:
- A function to check if the word has been completely guessed correctly.
- A function to print out the current state of the word, including letters guessed where correct, and placeholder blanks, “_” for all other un-guessed letters.
- A function that prints out all available letters for the user, so that he/she doesn’t repeat.
Once these core functions were completed, implementing the main game function was relatively straightforward, calling upon those functions and using a few extra variables to keep track of any mistakes and solicit user input for his/her guess. I thought it was a great idea to organize the pset into first building the three game functions one by one, and show exactly how each handled a different but critical piece of the overall game.
The course content is certainly picking up, but if the progression track is challenging and smart like it was this week, I’m looking forward to it.