Apr 16, 2025 | 243 words | 2 min read
8.2.2. Phone Number Converter#
Many companies use telephone numbers like \(555\text{-GET-FOOD}\) so that the number is easier for customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers as shown in Table 8.3.
Numbers |
Letters |
---|---|
\(2\) |
A,B, and C |
\(3\) |
D,E, and F |
\(4\) |
G,H, and I |
\(5\) |
J,K, and L |
\(6\) |
M,N, and O |
\(7\) |
P,Q,R, and S |
\(8\) |
T,U, and V |
\(9\) |
W,X,Y, and Z |
Write a new function named convert_number
that takes a phone number
string such as \(555\text{-GET-FOOD}\) as its only argument and returns the
telephone number with any alphabetic characters that appeared in the original
translated into their numeric equivalent. For example, if the argument is
\(555\text{-GET-FOOD}\), the function should return
\(555\text{-}438\text{-}3663\). Make sure the function can handle input
with both upper and lower case characters.
In your main
function, collect a phone number from the user, use your
convert_number
function to convert it to its numeric equivalent, and
then print the results as shown in the sample output.
Sample Output#
Use the values in Table 8.4 below to test your program.
Case |
Phone Numbers |
---|---|
1 |
555-GET-FOOD |
2 |
555-New-Cars |
3 |
555-Flowers |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 phone_number_converter_login.py Enter a telephone number: 555-GET-FOOD 555-GET-FOOD 555-438-3663
Case 2 Sample Output
$ python3 phone_number_converter_login.py Enter a telephone number: 555-New-Cars 555-New-Cars 555-639-2277
Case 3 Sample Output
$ python3 phone_number_converter_login.py Enter a telephone number: 555-Flowers 555-Flowers 555-3569377
Deliverables#
Save your finished program as phone_number_converter_login.py
,
replacing login
with your Purdue login. Then submit it along with
all the deliverables listed in
Table 8.5 below.
Deliverable |
Description |
---|---|
|
Your finished program. |
Screenshot(s) |
PNG(s) capturing all 3 test cases. |