Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python, using the starter code below, create a one player word game, similar to Scrabble. If the user enters 'D' to draw 7 letters

In python, using the starter code below, create a one player word game, similar to Scrabble.

If the user enters 'D' to draw

7 letters are removed from bag and given to user. If any letters are already in play they disappear (do not put back in bag)

If the user enters 'W' to make a word

  • If they enter a word that is not in the wordlist, it is invalid and they get no points. The letters in play remain the same.

  • If they enter a word that cannot be made from the letters currently in play, it is invalid and they get no points. The letters in play remain the same.

  • If they enter a word that theyve played it already, it is invalid and they get no points. The letters in play remain the same.

  • If they enter a valid word, they are awarded points for it based on the letters used. The letters used for the word are no longer in play and replaced with new letters.

If the user enters P to Print

They see all the valid words theyve played in the game so far, along with the points awarded for each one

If they press Q then quit

Each letter is worth a different amount of points. There are also several different amounts of each letter.image text in transcribed

Starter code:

def bag_of_letters(letter_dic):

letters=[] for letter,frequency in letter_dic.items(): for _ in range(frequency): letters.append(letter) return letters

def get_word_value(word,weights): value=0 for letter in word.upper(): if weights.get(letter) is not None: value+=weights.get(letter) return value

def get_wordlist(): ''' Function get-wordlist Params: nothoing Returns: a list of strings Does: retrieves a list of dictionary words from the built-in unix dictionary, which has been copied over. ''' try: infile = open('wordlist.txt', 'r') lines = infile.readlines() infile.close() except OSError: return [] for i in range(len(lines)): lines[i] = lines[i].strip(' ') lines[i] = lines[i].upper() if ' ' in lines[i]: lines[i] = lines[i].strip(' ') return lines

wordlist.txt file:

sap sat sad rat rap ram rag nap Nat mat map mad lap lag lad fat fan fad fin fit lid lip lit mid mitt nit nip rid rig rim
Points Letters A, E, I, O, U, L, N, S, T,R D,G B, C, M, P F, H, V, W, Y 4 J, X 10 Seven letters are in play at a time, and they're chosen at random from a big bag of 100 letters. Most letters have more than one instance in the bag, following these frequencies: Frequency Letters J, K, Q, X, Z B, C, F, H, M, P, V, W, Y, blank 4 D, L, S, U N, R, T A, I 12 Points Letters A, E, I, O, U, L, N, S, T,R D,G B, C, M, P F, H, V, W, Y 4 J, X 10 Seven letters are in play at a time, and they're chosen at random from a big bag of 100 letters. Most letters have more than one instance in the bag, following these frequencies: Frequency Letters J, K, Q, X, Z B, C, F, H, M, P, V, W, Y, blank 4 D, L, S, U N, R, T A, I 12

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions