Convert the Number
Given a number having ten digits, convert it to a string following the below-mentioned rules.
Rules for conversion:
1.separate the number into a set of four-three-three digits
2.Use the following prefixes for successive digits
a.Single numbers: just read them separately
b.Two consecutive numbers: double
c.Three consecutive numbers: triple
d.Four consecutive numbers: quadruple
Input
The first line of input is a string of ten digits.
Sample Input1
9887666668
Sample Output1
nine double eight seven triple six double six eight
Sample Input2
9090407368
Sample Output2
nine zero nine zero four zero seven three six eight
import itertools
digits = {'0': 'zero', '1': 'one', '2': 'two', '3': 'three', '4': 'four', '5': 'five', '6': 'six', '7': 'seven',
'8': 'eight', '9': 'nine'}
prefix = {2: 'double', 3: 'triple', 4: 'quadruple'}
tel = input()
rez = []
for substr in [tel[:4], tel[4:7], tel[7:]]:
for k, g in itertools.groupby(substr):
n = len(list(g))
if n > 1:
rez.append(prefix[n])
rez.append(digits[k])
print(' '.join(rez))
Comments
Leave a comment