How to convert numbers into strings in python? 1 -> 'one'
If i want a program where I let the user input a number (e.g. 1, 13, 4354)
how can i get it to print (one, thirteen, four three five four) does that
make sense? if it's two digit, print it as though it's joined (thirty-one)
but if it's more than 2 just print them sepretly, one the same line joined
with a space, I tried to do this with a dictionary, and I think it's
possible, but i can't figure out how to do it?
l = input('Enter the number: ')
if len(l) > 2:
nums = {'1':'one',
'2':'two',
'3':'three',
'4':'four',
'5':'five',
'6':'six',
'7':'seven',
'8':'eight',
'9':'nine'}
elif len(l) == 2:
tens = {'1}'how
for k, v in nums.items():
print(k, v)
This is obviously a wrong code, but I would like the finished result to
look something like this? thanks in advance!
No comments:
Post a Comment