Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having a letter mapped with its respective score
dict = fromList([("A",1), ("B",3), ("C", 3), ("E", 1), ("D", 2), ("G", 2), ("F", 4), ("I", 1), ("H", 4), ("K", 5), ("J", 8), ("M", 3), ("L", 1), ("O", 1), ("N", 1), ("Q", 10), ("P", 3), ("S", 1), ("R", 1), ("U", 1), ("T", 1), ("W", 4), ("V", 4), ("Y", 4), ("X", 8), ("Z", 10)])

If the main send a word to the function the function should return the score with respect to the dict and the letters in the word.
EX:- Main :- APPLE
Function should return :- 9
(A Score)1+(P Score)3 +(P Score)3 + (L Score) 1+(E Score)1 = 9
Posted

1 solution

Read the characters of the word one character at a time, locate the correct value for the letter you read in (might want to force to upper case at this point), and sum the values.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900