Python please: Using the template code as a starting point, write a program that reads a string of letters as input and produces output that is either a number or an error message. The output number should equal the sum of the values assigned to the letters (defined below). The program should output the error message if the input contains any characters that are not defined below. The error message should read "Error: Input contains an invalid character. Valid input characters are A, E, J, O, T, Z, YY." Your template code creates a list of letters and assigns each letter a number value: Letter Number A 1 E 5 J 10 O 15 T 20 Z 26 YY 50
Python please:
Using the template code as a starting point, write a
Your template code creates a list of letters and assigns each letter a number value:
Letter | Number |
---|---|
A | 1 |
E | 5 |
J | 10 |
O | 15 |
T | 20 |
Z | 26 |
YY | 50 |
NOTE 1: The final value in the list (YY) is a two-letter combination that must appear in full in order to be considered valid input.
NOTE 2: A space is not a valid input character.
HINT: You may use string[start:end] to parse the input string and extract the numeric integer for the "YY" combination.
Example 1: If the input is
TEA
the output should be
26
Example 2: If the input is
JOYY
output should be
75
Example 3: If the input is
JOY
the output should be
Error: Input contains an invalid character. Valid input characters are A, E, J, O, T, Z, YY.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images