+ 1

question

someone help me, please. A, B, and C = 2 D, E, and F = 3 G, H, and I = 4 J, K, and L = 5 M, N, and O = 6 P, Q, R, and S = 7 T, U, and V = 8 W, X, Y, and Z = 9 Write a program that asks the user to enter a 10-character telephone number in the format XXX-XXX-XXXX. The application should display the telephone number with any alphabetic characters that appeared in the original translated to their numeric equivalent. For example, if the user enters 555-GET-FOOD the application should display 555-438-366

23rd Oct 2017, 9:05 PM
angela
angela  - avatar
2 Answers
+ 3
""" Regex is useful for testing validity of user string pattern entry, but doesn't directly help to answer the question wich doesn't specify if user entry need to be tested or is supposed to already be a valid one ;P """ import re inp = input("Enter a 10-digits/letters phone number: ").upper() out = "" alpha2num = "22233344455566677778889999" # testing string validity (ccc-ccc-cccc / accept both uppercase and lowercase characters) if re.match(r"^[\dA-Za-z]{3}-[\dA-Za-z]{3}-[\dA-Za-z]{4}
quot;,inp) is not None: # converting letters to digit for c in inp: i = ord(c) if i > 64 and i < 91: out += alpha2num[i-65] else: out += c print("Only digits number is: "+out) else: print("Not a valid phone number (xxx-xxx-xxxx)...")
24th Oct 2017, 4:15 AM
visph
visph - avatar
+ 2
is this your homework?😕 try using RegExp for that problem.
23rd Oct 2017, 11:39 PM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar