Answer to Question #296352 in Python for Ram

Question #296352

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 triplesix double six eight





Sample Input2



9090407368



Sample Output2



nine zero nine zero four zero seven three six eight

1
Expert's answer
2022-02-11T18:45:07-0500
prefix = {'0': 'zero ',
          '1': 'one ',
          '2': 'two ',
          '3': 'three ',
          '4': 'four ',
          '5': 'five ',
          '6': 'six ',
          '7': 'seven ',
          '8': 'eight ',
          '9': 'nine ',
          '': ''}
convert_string = ''
s = input('>')
s += ' '
count = 0
last_char = s[0]
for i in s[1:]:
    if last_char == i and count < 3:
        count += 1
    else:
        if count == 0:
            convert_string += prefix[last_char]
        elif count == 1:
            convert_string += 'double ' + prefix[last_char]
        elif count == 2:
            convert_string += 'triple ' + prefix[last_char]
        elif count == 3:
            convert_string += 'quadruple ' + prefix[last_char]
        last_char = i
        count = 0
print(convert_string)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS