I need to turn numbers from 1 - 99 into words. This is what I got so far:
num2words1 = {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'}
num2words2 = ['Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety']
def number(Number):
if (Number > 1) or (Number < 19):
return (num2words1[Number])
elif (Number > 20) or (Number < 99):
return (num2words2[Number])
else:
print("Number Out Of Range")
main()
def main():
num = eval(input("Please enter a number between 0 and 99: "))
number(num)
main()
Now, the BIGGEST problem that I have so far is that the if, elif and else statements DO NOT seem to work. Only the first if statement runs.
The second problem is creating the string version of the numbers from 20-99....
P.S. Yes, I know about the num2word library, but I am not allowed to use it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…