In: Computer Science
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
Note: This function relies on scrabblePoints. Function you solved in Question 2.
Implement function declareWinner(player1Word = “skip”, player2Word = “skip”) that returns either “Player 1 Wins!”, “Player 2 Wins!”, “It’s a Tie”, “Player 1 Skipped Round”, “Player 2 Skipped Round”, “Both Players Skipped Round”. The player1Word and player2Word parameters are both type string. Assume input is always valid. This function should call on the function scrabblePoints to earn credit.
[No built-in function or method needed]
Examples:
player1Word = “PYTHON”
player2Word = “Pizza”
print(declareWinner(player1Word, player2Word))
returns:
Player 2 Wins!
print(declareWinner(player1Word))
returns:
Player 2 Skipped Round
Please do the second function only. I just needed to add the first function for reference
Screenshot:
Code:
#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 }
#def scrabblePoint(word):
def declareWinner(player1Word="skip",player2Word="skip"):
if player1Word=="skip":
return "Player 1 Skipped Round"
elif player2Word=="skip":
return "Player 2 Skipped Round"
elif scrabblePoint(player1Word)>scrabblePoint(player2Word):
return "Player 1 Wins!"
elif scrabblePoint(player2Word)>scrabblePoint(player1Word):
return "Player 2 Wins!"
else:
return "It’s a Tie"
player1Word="PYTHON"
player2Word="Pizza"
print(declareWinner(player1Word,player2Word))
print(declareWinner(player1Word))