2 = ABC , 3 = DEF , 4 = GHI , 5= JKL = 6 =MNO , 7= PQRS, 8= TUV
, 9 = WXYZ ( 1 has no letters with it).
Write a function named converted_number which accepts a phone
number in the form (900)HEY-MATE and returns the formatted phone
number equivalent (900)439-6283.
In python!
Please and thanks!
def convertNo(var,has):
var = str(var[5:]) #since starting 6 terms are fixed (900)
ans = ""
i = 0
while i < len(var):
for k,v in has.items():
if var[i].upper() in v:
ans += str(k)
i+=1
return(ans)
has = {
1:[""],
2: ["A","B","C"],
3:["D","E","F"],
4:["G","H","I"],
5:["J","K","L"],
6:["M","N","O"],
7:["P","Q","R","S"],
8:["T","U","V"],
9:["W","X","Y","Z"],
"-":["-"]
} #created a has map according to need
var = input("enter string")
res = convertNo(var,has)
print("(900)"+res)
If you have any doubt regarding thid program then you amy ask in comment section
Get Answers For Free
Most questions answered within 1 hours.