Code Challenge 02 - Word Values Part II - A Simple Game - Review

PyBites, Fri 20 January 2017, Challenges

code review, codechallenges, game, github, itertools, learning, scrabble

It's Friday again so we review the code challenge of this week. It's never late to join, just fork our challenges repo and start coding.

A possible solution

See here for the complete solution.

Some learnings:

We use the calc_word_value and max_word_value methods from challenge 01 to calculate which word has the most value.

The rest is main() calling the methods and outputting (as was provided in the template).


We got a request in the comments for tests to verify the work. Good idea, they are here.

$ python 
Ran 6 tests in 0.056s


Its fun (addictive?) to play :)

[[email protected] 02 (master)]$ python 
Letters drawn: T, I, I, G, T, T, L
Form a valid word: tig
Word chosen: TIG (value: 4)
Optimal word possible: gilt (value: 5)
You scored: 80.0
[[email protected] 02 (master)]$ python 
Letters drawn: O, N, V, R, A, Z, H
Form a valid word: zar
Word chosen: ZAR (value: 12)
Optimal word possible: zonar (value: 14)
You scored: 85.7
[[email protected] 02 (master)]$ python 
Letters drawn: E, P, A, E, I, O, A
Form a valid word: pi
Word chosen: PI (value: 4)
Optimal word possible: apio (value: 6)
You scored: 66.7
[[email protected] 02 (master)]$ python 
Letters drawn: B, R, C, O, O, E, O
Form a valid word: broc
Not a valid dictionary word, try again
Form a valid word: f
One or more characters not in draw, try again
Form a valid word: bore
Word chosen: BORE (value: 6)
Optimal word possible: boce (value: 8)
You scored: 75.0

Any issues or feedback?

What did you learn this challenge? Feel free to share you code in the comments below.

How are you experiencing these challenges? You like the format? What can we do differently and/or better?


Monday we will be back with a new challenge, stay tuned ...

Again to start coding fork our challenges repo or sync it if you already forked it.

PyBites Python Tips

Do you want to get 250+ concise and applicable Python tips in an ebook that will cost you less than 10 bucks (future updates included), check it out here.

Get our Python Tips Book

"The discussions are succinct yet thorough enough to give you a solid grasp of the particular problem. I just wish I would have had this book when I started learning Python." - Daniel H

"Bob and Julian are the masters at aggregating these small snippets of code that can really make certain aspects of coding easier." - Jesse B

"This is now my favourite first Python go-to reference." - Anthony L

"Do you ever go on one of those cooking websites for a recipe and have to scroll for what feels like an eternity to get to the ingredients and the 4 steps the recipe actually takes? This is the opposite of that." - Sergio S

Get the book