I tried to not dictionary everything, but the exceptions are real. Lots of amusing output as I got closer, that I'll paste for your enjoyment. I did actually get it working though :P
#15
fiveteen
# 818
eight hundred eightteen eight
# 101
one hundred oneteen one
# 654
six hundred six hundred six hundred
#!/usr/bin/env python
# 0 < num < 1000
num_map={'1':'one','2':'two','3':'three','4':'four','5':'five','6':'six','7':'seven','8':'eight','9':'nine','10':'ten','11':'eleven','12':'twelve','13':'thirteen','14':'fourteen','15':'fifteen','18':'eighteen','20':'twenty','30':'thirty','50':'fifty','80':'eighty'}num=input("Enter a number: ").lstrip('0')inum=int(num)word=''for_inrange(len(num)):ifnuminnum_map:word=f'{word} {num_map[num]}'breakelifinum<20:lsi=num[1]word=f'{word} {num_map[lsi]}teen'breakelifinum<100:tendigit=num[0]tenword=f'{tendigit}0'iff'{tenword}'innum_map:word=f'{word} {num_map[tenword]}'else:word=f'{word} {num_map[tendigit]}ty'elifinum<1000:hdigit=num[0]word=f'{word} {num_map[hdigit]} hundred'num=num[1:].lstrip('0')inum=int(num)print(word.strip())
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I tried to not dictionary everything, but the exceptions are real. Lots of amusing output as I got closer, that I'll paste for your enjoyment. I did actually get it working though :P