convert ten digits into a string:
rules for conversion:
sample input:9966777819
output should be:double nine double six triple seven eight one nine
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]}")
Comments
Leave a comment