In this lab, you will: Use input() to read line Use for loop to go over all symbols in the line Use created a dictionary to get the corresponding value for a certain key Instructions Scrabble is a word game in which words are constructed from letter tiles, each letter tile containing a point value. The value of a word is the sum of each tile's points added to any points provided by the word's placement on the game board. Write a program using the given dictionary of letters (keys) and point (values) that takes a word as input and outputs the base total value of the word (before being put onto a board). Implement function create_scrabble to calculate the total points for the given string (the function's parameter) and return the value for the word. Outside the function, print the total value for the word. Ex: If the input is: PYTHON the output is: 14 def create_scrabble (user_input): tile_dict = { 'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4, 'I': 1, 'J': 8, 'K': 5, 'L': 1, 'M': 3, 'N': 1, 'O': 1, 'P': 3, 'Q': 10, 'R': 1, 'S': 1, 'T': 1, 'U': 1, 'V': 4, 'W': 4, 'X': 8, 'Y': 4, 'Z': 10 } if __name__ == "__main__":
In this lab, you will:
- Use input() to read line
- Use for loop to go over all symbols in the line
- Use created a dictionary to get the corresponding value for a certain key
Instructions
Scrabble is a word game in which words are constructed from letter tiles, each letter tile containing a point value. The value of a word is the sum of each tile's points added to any points provided by the word's placement on the game board.
Write a program using the given dictionary of letters (keys) and point (values) that takes a word as input and outputs the base total value of the word (before being put onto a board). Implement function create_scrabble to calculate the total points for the given string (the function's parameter) and return the value for the word. Outside the function, print the total value for the word.
Ex: If the input is:
PYTHON
the output is:
14
def create_scrabble (user_input):
tile_dict = { 'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4, 'I': 1, 'J': 8,
'K': 5, 'L': 1, 'M': 3, 'N': 1, 'O': 1, 'P': 3, 'Q': 10, 'R': 1, 'S': 1, 'T': 1,
'U': 1, 'V': 4, 'W': 4, 'X': 8, 'Y': 4, 'Z': 10 }
if __name__ == "__main__":
Step-1: Start
Step-2: Declare a variable and take input from user
Step-3: Call a function create_scrabble(user_input):
Step-3.1: Create a dictionary
Step-3.2: Declare a variable point to calculate the values
Step-3.3: Iterate each letter given by user and compare with dictionary item if match then add the value in point
Step-3.4: Print point
Step-4: Stop
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images