Question: Write a Python program that takes a Scrabble rack as a command-line argument and prints all valid Scrabble English words that can be constructed from

Write a Python program that takes a Scrabble rack as a command-line argument and prints all "valid Scrabble English" words that can be constructed from that rack, along with their Scrabble scores, sorted by score. "valid Scrabble English" words are provided in the data source below. A Scrabble rack is made up of 2 to 7 characters.

Below are the requirements for the program:

  • This needs to be able to be run as a command line tool as shown below (not an input statement!)
  • Name the python file: scrabble.py
  • Make a separate module named wordscore which contains at a minimum a function called score_word. This score_word function will take each word and return the score (scoring dictionary is described below). Import this function into your main scrabble.py program.
  • Allow anywhere from 2-7 character tiles (letters A-Z) to be inputted.
  • Do not restrict the number of same tiles (e.g., a user is allowed to input ZZZZZQQ).
  • Output the total list of valid Scrabble words that can be constructed from the rack as (score, word) tuples, sorted by the score and then by the word alphabetically as shown in the first example below.
  • Then output 'Total number of words:' and the total number.
  • You need to handle input errors from the user and suggest what that error might be caused by and how to fix it (i.e., a helpful error message)
  • Implement wildcards as either * or ?. There can be a total of only two wild cards in any user input (that is, one of each character: one * and one ?). Only use the * and ? as wildcard characters. A wildcard character can take any value A-Z. Replace the wildcard symbol with the letter in your answer (see the second example below).
  • Wildcard characters are scored as 0 points, just like in the real Scrabble game. A two wildcard word can be made, should be outputted and scored as 0 points.
    • In a wildcard case where the same word can be made with or without the wildcard, display the highest score. For example: given the input 'I?F', the word 'if' can be made with the wildcard '?F' as well as the letters 'IF'. Since using the letters 'IF' scores higher, display that score.
  • For partial credit, your program should take less than one minute to run with 2 wildcards in the input. For full credit, the program needs to run with 2 wildcards in less than 30 seconds.
  • Write docstrings for the functions and puts comments in your code.
  • You may only use the Python standard library in this assignment. However, any function in the standard library is allowed.

An example invocation and output:

$ python scrabble.py "ZAEFIEE"

(17, feaze)

(17, feeze)

(16, faze)

(15, fez)

(15, fiz)

(12, zea)

(12, zee)

(11, za)

(6, fae)

(6, fee)

(6, fie)

(5, ef)

(5, fa)

(5, fe)

(5, if)

(2, ae)

(2, ai)

(2, ea)

(2, ee)

Total number of words: 19

An example wildcard invocation and output:

$ python scrabble.py "?F"

(4, ef)

(4, fa)

(4, fe)

(4, fy)

(4, if)

(4, of)

Total number of words: 6

Extra Credit (+10 points):

Requirements:

  • Allow a user to specify that a certain letter has to be at a certain location. For the extra credit, locations of certain letters must be specified at the command line, and may not be some sort of user prompt. How you do this is up to you!
  • This needs to be included and called from your regular scrabble.py file and work with the base requirements above. That is, your program must work with or without the extra credit portion and the extra credit cannot be in a different .py file.
  • Please put comments, any assumptions you made, and a sample of how to run your extra credit in the extra credit cell of this notebook below - it is the last cell. If there is not an example of how to run the extra credit in this cell we will assume that you did not do the extra credit part!

The Data

The file: http://courses.cms.caltech.edu/cs11/material/advjava/lab1/sowpods.zip or https://drive.google.com/file/d/1ewUiZL_4HanCDsaYB5pcKEgqjMFVgGnh/view?usp=sharing contains all "valid Scrabble English" words in the official words list, one word per line. You should download the word file and keep it in your repository so that the program is standalone (instead of accessing it over the web from Python).

You can read data from a text file with the following code:

with open("sowpods.txt","r") as infile:

raw_input = infile.readlines()

data = [datum.strip(' ') for datum in raw_input]

This will show the first 6 words:

print(data[0:6])

Please use the dictionary below containing the letters and their Scrabble values:

scores = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2,

"f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3,

"l": 1, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1,

"r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4,

"x": 8, "z": 10}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!