In: Computer Science
I have attached the screenshot for both code and output.
CODE-
#Taking input
number=input("Enter the phone number\n")
#Looping through the string
for i in number:
#If character is alphabet then convert it to numeric
if i.isalpha():
if ord(i)<=67:
print("2",end="")
elif ord(i)<=70:
print("3",end="")
elif ord(i)<=73:
print("4",end="")
elif ord(i)<=76:
print("5",end="")
elif ord(i)<=79:
print("6",end="")
elif ord(i)<=83:
print("7",end="")
elif ord(i)<=86:
print("8",end="")
elif ord(i)<=90:
print("9",end="")
#Else print as it is
else:
print(i,end="")
SCREENSHOTS-