Answer to Question #266009 in Python for vijay

Question #266009

write a program to read the mobile number in human form. The 10 digit mobile number should be divide into 4-3-3 format . If it has continues 4 numbers it should be pronounced as quadruple , 3 numbers as thriple , 2 numbers as double.

input:- 9977222208

Here system should divide itself in 4-3-3 format like 9977 222 208

output: double nine double seven thriple two two zero eight

input:- 1111999228

output:- quadruple one thriple nine double two eight


1
Expert's answer
2021-11-15T07:38:52-0500
dict_1 = {1:"", 2:"double ", 3:"thriple ", 4:"quadruple "}
dict_2 = {1:"one ", 2:"two ", 3:"three ", 4:"four ", 5:"five ",
6:"six ", 7:"seven ", 8:"eight ",9:"nine ", 0:"zero "}
def num_to_human(n:str):
	s = ""
	reapet = 1
	for i in range(len(n)):
		if i >= len(n)-1 or n[i] != n[i+1]:
			s += dict_1[reapet] + dict_2[int(n[i])]
			reapet = 1
		elif n[i] == n[i+1]:
			reapet += 1
	return s


in_num = input()
human_readble = ""
if len(in_num) == 10:
	in_num = [in_num[:4], in_num[4:7], in_num[7:]]


	for el in in_num:
		human_readble += num_to_human(el)


print(human_readble)

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