Question
pls use python do this Problem 1. Word scores The first step is to implement some code that allows us to calculate the score for
pls use python do this Problem 1. Word scores
The first step is to implement some code that allows us to calculate the score for a single word.
The function get_word_score should accept a string of lowercase letters as input (a word) and return the integer score for that word, using the games scoring rules.
Fill in the code for get_word_score in ps3a.py:
def get_word_score(word, n):
"""
Returns the score for a word. Assumes the word is a
valid word.
The score for a word is the sum of the points for letters
in the word multiplied by the length of the word, plus 50
points if all n letters are used on the first go.
Letters are scored as in Scrabble; A is worth 1, B is
worth 3, C is worth 3, D is worth 2, E is worth 1, and so on.
word: string (lowercase letters)
returns: int >= 0
"""
# TO DO...
You may assume that the input word is always either a string of lowercase letters, or the empty string "". You will want to use the SCRABBLE_LETTER_VALUES dictionary defined at the top of ps3a.py. You should not change its value.
Do not assume that there are always 7 letters in a hand! The parameter n is the number of letters required for a bonus score (the maximum number of letters in the hand).
Testing: If this function is implemented properly, and you run test_ps3a.py, you should see that the test_get_word_score()tests pass. Also test your implementation of get_word_score, using some reasonable English words.
Problem 1. Word scores
The first step is to implement some code that allows us to calculate the score for a single word.
The function get_word_score should accept a string of lowercase letters as input (a word) and return the integer score for that word, using the games scoring rules.
Fill in the code for get_word_score in ps3a.py:
def get_word_score(word, n):
"""
Returns the score for a word. Assumes the word is a
valid word.
The score for a word is the sum of the points for letters
in the word multiplied by the length of the word, plus 50
points if all n letters are used on the first go.
Letters are scored as in Scrabble; A is worth 1, B is
worth 3, C is worth 3, D is worth 2, E is worth 1, and so on.
word: string (lowercase letters)
returns: int >= 0
"""
# TO DO...
You may assume that the input word is always either a string of lowercase letters, or the empty string "". You will want to use the SCRABBLE_LETTER_VALUES dictionary defined at the top of ps3a.py. You should not change its value.
Do not assume that there are always 7 letters in a hand! The parameter n is the number of letters required for a bonus score (the maximum number of letters in the hand).
Testing: If this function is implemented properly, and you run test_ps3a.py, you should see that the test_get_word_score()tests pass. Also test your implementation of get_word_score, using some reasonable English words.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started