Answer the question
In order to leave comments, you need to log in
How to make a calculator that will give the result in words?
How to make a calculator that can subtract and add numbers from 0 to 63. It is desirable that it accepts values in the form of text, for example: 10+1 or 59-5. And he gave out the answers in text, in English: for example, "Eleven" or "Fifty four".
I have already made it output numbers from 0 to 20 and after 10 words, but how to make it output "Fifty four" I can't figure out.
def counter():
words = {0: 'zero', 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',
16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 30: 'thirty', 40: 'forty',
50: 'fifty', 60: 'sixty'}
string = input()
result = eval(string)
if result >=0 and result <= 63:
if result >= 0 and result <= 20:
for k, v in words.items():
if k == result:
print(v)
elif result >= 21 and result <= 63:
for k, v in words.items():
if k == result:
print(v)
# else:
# dozen = (result - (result % 10))
# units = result % 10
# if dozen == k and units == k:
# print(v + v)
# print(dozen + units)
counter()
Answer the question
In order to leave comments, you need to log in
There are up to a hundred, you can just take a dozen and the remainder, well, write out
result = 43
if result > 20 and result < 63:
if result in words:
print(words[result])
else:
q, mod = divmod(result, 10)
print(words[q*10], words[mod])
well, how to make a calculator, I think you’ll find it in google And
look at the translation of a number from numbers into words in a turnip
yes there on js but the logic is the same
https://github.com/Vorfall/human-readable-number/b...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question