Check if Word Equals Summation of Two Words
Below is the Python code to determine whether the summation of the numerical values of firstWord
and secondWord
equals the numerical value of targetWord
, following the given constraints and using lower case English letters ‘a’ through ‘j’.
|
|
Explanation:
- Define a Function to Convert Word: We define a function
get_value
that takes a word and converts it into a numerical value according to the rules specified in the problem. This involves converting each letter to its corresponding value and concatenating them together. - Convert Words to Numerical Values: We call the
get_value
function onfirstWord
,secondWord
, andtargetWord
to convert them into their corresponding numerical values. - Check Summation: We check if the summation of the numerical values of
firstWord
andsecondWord
equals the numerical value oftargetWord
. If it does, we returnTrue
; otherwise, we returnFalse
.