forked from HuskyChaos/pythonScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
numberToWord.py
executable file
·61 lines (50 loc) · 1.8 KB
/
numberToWord.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def ones(x):
wl = ["", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
return wl[x]
def tens(x):
wl = ["", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"]
return wl[x-1]
def special(x):
wl = ["Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"]
return wl[x]
def main(x):
# inputNumber = input("Enter a number: ")
print(f'Enter number: {x}')
inputNumber = x
inputNumber = inputNumber[::-1]
ans = list()
for i in range(len(inputNumber)):
if i == 0:
ans.append(ones((int(inputNumber[i]))))
elif i == 1:
if inputNumber[i] == "1":
ans.remove(ans[i-1])
ans.append(special(int(inputNumber[i-1])))
elif inputNumber[i] == "0":
ans.append(tens(1))
else:
if inputNumber[i-1] == "0":
ans.remove(ans[i-1])
ans.append(tens(int(inputNumber[i])))
elif i == 2:
ans.append("Hundred")
ans.append(ones(int(inputNumber[i])))
elif i == 3:
ans.append("Thousand")
ans.append(ones(int(inputNumber[i])))
elif i == 4:
if inputNumber[i] == "1":
ans.remove(ans[i-1])
ans.append(special(int(inputNumber[i-1])))
else:
if ans[i-1] == "Zero":
ans.remove(ans[i-1])
ans.append(tens(int(inputNumber[i])))
# print(list(reversed(ans)))
# print("===============================")
print(" ".join(list(reversed(ans))))
print("===============================")
if __name__ == "__main__":
# while True:
for i in range(90,121):
main(str(i))