Answer to Question #281888 in Python for sai

Question #281888

convert ten digits into a string:

rules for conversion:

  1. separate the number into a set of four-three-three
  2. Two consecutive numbers: double
  3. Three consecutive numbers: triple
  4. Four consecutive numbers: quadruple

sample input:9966777819

output should be:double nine double six triple seven eight one nine


1
Expert's answer
2021-12-22T14:19:38-0500

num_in_digits = input()


dig_to_alphabet = {"0":"zero","1":"one","2":"two","3":"three","4":"four","5":"five","6":"six","7":"seven","8":"eight","9":"nine"}

double = {2:"double",3:"triple",4:"quadruple"}


temp=""

l=0


for i in range(len(num_in_digits)):

  temp = num_in_digits[i]

  l = l + 1

  if (i + 1 < len(num_in_digits)):

    if num_in_digits[i] != num_in_digits[i + 1]:

      if l == 1:

        print(f"{dig_to_alphabet[temp]} ",end="")

      else:

        print(f"{double[l]} {dig_to_alphabet[temp]} ",end="")

      temp = num_in_digits[i + 1]

      l = 0

  else:

    print(f"{double[l]} {dig_to_alphabet[temp]}")


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