Can any please do it by python program please It is (starting with python third
ID: 3577175 • Letter: C
Question
Can any please do it by python program please
It is (starting with python third edition) ! Many companies use telephone numbers like 555-GET-FooD so the number is easier for their customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion: 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 charactersthat appeared in the originai translated to their numeric equivalent. For example, if the user enters 555-GET- FOOD the application should display 555-438-3663. Design functions as needed.
Explanation / Answer
//save as phone.py
#Python 3.4
#Python program that prompts user to enter a phone number
#in 555-xxx-xxx then prints the phone number in numeric form
#main method
def main():
#dictionary that contains (key,value) pairs of corresponding
#letters of dictionary
phone_dict ={'A': '2','B': '2','C': '2','D': '3','E': '3',
'F': '3','G': '4','H': '4','I': '4','J': '5',
'K': '5','L': '5','M': '6','N': '6','O': '6',
'P': '7','Q': '7','R': '7','S': '7','T': '8',
'U': '8','V': '8','W': '9','X': '9','Y': '9',
'Z': '9'}
number = input('Enter an alpha-numeric phone number: ')
#create a list called result to add numeric value of phone number
result = []
#check a lentter n in number
for n in number:
#check if digit then append
if n.isdigit():
str(result.append(n))
#check if alphabet
elif n.isalpha():
#get the correcponding value of the key ,n
value = phone_dict.get(n.capitalize())
#append to result
result.append(value)
#check if n is '-'
elif n=='-':
result.append('-')
#print each letter in same line using end=''
for ch in result:
print(ch, end='')
#calling main method
main()
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.