6.00x: Recursion and Objects Week 3

This post is part of the 6.00x Intro to Computer Science and Programming series

Tower_of_Hanoi 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:

  1. A function to check if the word has been completely guessed correctly.
  2. 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.
  3. A function that prints out all available letters for the user, so that he/she doesn’t repeat.

Hangman-5Once 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.

Advertisements
This entry was posted in Education, Gaming and tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s