Monthly Archives: March 2015

Python: Problem Set 3

This problem set involves a word game somewhat like Scrabble. In Part A, the player is dealt a hand of semi-random letters and has to make as many valid words as she can. Some letters are weighted higher or lower when it comes to scoring. Some aspects of the game code are provided to begin with. The rest of the functions are left up to us to complete, then put together into a looping game where you can choose to start a New Game, Replay, or Exit. In Part B, a computer player is added, which will pick one or more valid words until no more can be made with the remaining letters.

Key take-aways from lecture:

  • floats are dangerous, e.g. 0.1 can only be approximated in binary
  • print(num) may show ‘0.1’ but use repr(num) to see what is actually being stored
  • When debugging, ask, “How could it have done what it did?”
  • It’s a better starting point than, “Why didn’t it do what I want?”
  • Use print statements in a manner similar to bisection search. Check here, then there.
  • Try to test against small input values and make tests repeatable

Part A

  • Scoring Words
  • Dealing with Hands
  • Word Validation
  • Playing a Hand
  • Playing a Game

Part B

  • Computer Chooses (best scoring first word and so on)
  • Computer’s Turn to Play
  • You or the Computer

Python: Problem Set 2

Problem set 2 involves two different problems. The first uses successive approximation to find the root of a function. If, like me, you need a refresher on the derivative of a polynomial, try http://www.freemathhelp.com/derivative-of-polynomial.html. The problem is actually broken down into distinct functions to help us get to the final answer.

The second problem is a bit more fun for those that prefer letters over number crunching. Implement your own game of hangman!

Successive Approximation

Hangman