In this we are going to see a basic program to convert python phone number in words to its equivalent digits in Python Programming Language.
def getPhoneNumber(s):
ph = ""
numbers = {
"one": '1',
'two': '2',
'three': '3',
'four': '4',
'five': '5',
'six': '6',
'seven': '7',
'eight': '8',
'nine': '9',
'zero': '0'
}
numlist = s.split(" ")
numlist = iter(numlist)
for num in numlist:
# print(num)
if num in numbers:
ph = ph+numbers[num]
elif num == 'double':
nextnum = numbers[next(numlist)]
ph = ph+nextnum+nextnum
elif num == 'triple':
nextnum = numbers[next(numlist)]
ph = ph+nextnum+nextnum+nextnum
return ph
def main():
strNum = input(
"Enter phone number in words using keywords double and triple if necessary: ")
print("The phone number in digits is: ", getPhoneNumber(strNum))
main()
# Coded by Shreya Idate
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP