if statements, for loops, strings, mods
When you rent a car from an agency, the key ring has several pieces of information: license plate, make and year of car, and usually a special code. This code could be used for some data processing within the company's computers.
This lab will practice determining that special car rental code from the license plate.
Here's how to convert a license plate into a car rental code:
- Ask the user for a license plate. A license plate consists of digits and capital letters of the alphabet only, like
- Add up the ASCII values of the letters and the integer values of the digits, e.g.
6 + 0 + 7 + 67 + 80 + 82 + 2 + 1 = 245 for our first example above.
- Take this sum and map it onto a numeric representation of one of the 26 letters of the alphabet (where A’s numeric representation is 0, B’s numeric representation is 1, etc.). For example, 245 should map to an 11.
- Use this number (say 11) to determine the 11th letter in the alphabet after the letter A: the 11th letter after A is L.
- Combine the letter and the sum to make the car ID. So far, it's:
- Extract the substring of letters out of the original license plate – in this case
CPR. Convert the letters to lowercase and place the letters at the end of the car id to get – and print – the final answer:
Plate 607CPR21 = L245cpr
Useful tools to solve the problem