Question

In: Computer Science

Use this constant dictionary as a global variable: tile_dict = { 'A': 1, 'B': 3, 'C':...

Use this constant dictionary as a global variable:

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 }

Implement function scrabblePoints(word) that returns the calculated points for the word based on the tile_dict above. The word parameter is a string. This function takes the string and evaluates the points based on each letter in the word (points per letter is set by the global dictionary). P or p is worth the same points. No points calculated for anything that is not A-Z or a-z.

[You may use upper() and isalpha() ONLY and no other method or built-in function]

Examples:

word = “PYTHON”

print(scrabblePoints(word))

returns:

14

word = “hello!!”

print(scrabblePoints(word))

returns:

8

word = “@#$=!!”

print(scrabblePoints(word))

returns:

0

Solutions

Expert Solution

Code

#defin ethe dictionary

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 }

#create and define teh scrablle method

def scrabblePoints(words):

global tile_dict

points = 0 #set initital points 0

#itearte each character in words:

for i in list(words):

#check if the current chacatre is alphabet

if i.isalpha():

points += tile_dict[i.upper()]

#return point

return points

word = "PYTHON"

print(scrabblePoints(word))

word = "hello!!"

print(scrabblePoints(word))

word = "@#$=!!"

print(scrabblePoints(word))


Screenshot

Output


Related Solutions

Use this constant dictionary as a global variable: tile_dict = { 'A': 1, 'B': 3, 'C':...
Use this constant dictionary as a global variable: 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 } Implement function scrabblePoints(word) that returns the calculated points for the word based on the tile_dict above....
Use this constant dictionary as a global variable: tile_dict = { 'A': 1, 'B': 3, 'C':...
Use this constant dictionary as a global variable: 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 } Implement function scrabblePoints(word) that returns the calculated points for the word based on the tile_dict above....
#Python Given a dictionary gradeCounts = { "A": 8, "D": 3, "B": 15, "F": 2, "C":...
#Python Given a dictionary gradeCounts = { "A": 8, "D": 3, "B": 15, "F": 2, "C": 6 } write the Python statement(s) to print: a) all the keys. b) all the values. c) all the key and value pairs. d) all of the key and value pairs in key order. e) the average value. f) a chart similar to the following in which each row contains a key followed by a number of asterisks equal to the key’s data value....
Define the following concepts: (a) constant capital; (b) variable capital; (c) rate of surplus value; (d)...
Define the following concepts: (a) constant capital; (b) variable capital; (c) rate of surplus value; (d) mass of surplus value.
Never declare a C++ global variable in this class. But global constants are ok. unsigned Size1...
Never declare a C++ global variable in this class. But global constants are ok. unsigned Size1 = 100; // never do this at global scope const unsigned Size2 = 120; // this is ok (but probably not very helpful) Don't use the string class and don't use system functions for math (like pow) or strings (like strlen). These functions are meant to be short and simple; if you're writing something long and complicated, look for a simpler solution. void countdown(...
Create two functions that you can use for a dictionary manager: 1. remove_item(dictionary,key): a function that...
Create two functions that you can use for a dictionary manager: 1. remove_item(dictionary,key): a function that removes the item with the supplied key from the dictionary, if it exits. If the input key doesn’t exist in the dictionary, print out a message saying that the new item has not been removed because there is no matching key in the dictionary. Your function should not produce a Python error if the item does not exist; 2. add_new_item(dictionary,key,value): a function that adds...
A and B react as follows: A + B = C + D. The equilibrium constant...
A and B react as follows: A + B = C + D. The equilibrium constant is 2.0 x 10^3. If 0.30 mol of A and 0.80 mol of B are mixed in 1 L, what are the concentrations for A, B, C, and D after reaction?
******Show work, no Exel/Spss please!!!!****** Variable B Variable A    1    2    3   ...
******Show work, no Exel/Spss please!!!!****** Variable B Variable A    1    2    3    1 5 4 4 2 6 9 1 3 7 4 1 5 2 3 4 2 6 6 5 2 7 7 3 4 5 3 3 4 2 3 8 1. Given the following data, what is the value of F crit for the column effect (variable b) *Hint: don't forget to evaluate a numerator (for variable B) and denominator df (within):...
Use boolean algebra to prove that: (A^- *B*C^-) + (A^- *B*C) + (A* B^- *C) +...
Use boolean algebra to prove that: (A^- *B*C^-) + (A^- *B*C) + (A* B^- *C) + (A*B* C^-) + (A*B*C)= (A+B)*(B+C) A^- is same as "not A" please show steps to getting the left side to equal the right side, use boolean algebra properties such as distributive, absorption,etc
Variable 1 Variable 2 Variable 3 Variable 1 Variable 2 - .18 Variable 3 - .30...
Variable 1 Variable 2 Variable 3 Variable 1 Variable 2 - .18 Variable 3 - .30 .27 Variable 4 - .74* .60* .34 Note: * = p < .05 A) What is the proportion of variance in variable 1 that is predicted by variable 3? B) What is the proportion of the variance in variable 2 that is not predicted by variable 4? What are the steps I need to take to solve this problem?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT