Answer to Question #282378 in Python for Siva

Question #282378

convert ten digits into a string:



rules for conversion:



separate the number into a set of four-three-three


Two consecutive numbers: double


Three consecutive numbers: triple


Four consecutive numbers: quadruple



sample input:9966777819



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



Sample input2: 9999



Output should be: quadruple nine



Sample input3: 88



Output should be: double eight

1
Expert's answer
2021-12-24T01:20:26-0500
def num_to_str(num:str):


	prefix = ('', 'double ', 'triple ', 'quadruple ')
	root = ('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine')
	reapets = 0
	res = []
	for i in range(len(num)):
		if (i < (len(num)-1)) and (num[i] == num[i+1]):
			reapets += 1
		else:
			res.append(prefix[reapets] + root[int(num[i])])
			reapets = 0
	return ' '.join(res)
for i in range(3):
	number = input()
	res = []
	i = 4
	num = number[:4]
	while num:
		res.append(num_to_str(num))
		num = number[i:i+3]
		i += 3
	print(' '.join(res))

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