-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChequeMaker_Python.py
More file actions
187 lines (132 loc) · 6.34 KB
/
ChequeMaker_Python.py
File metadata and controls
187 lines (132 loc) · 6.34 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import re
global suffixes
suffixes = ["", " Thousand", " Million", " Billion", " Trillion"]
global cents
cents = ["", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
global ones
ones = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
global after_ten
after_ten = ["Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"]
global tens
tens = ["Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety", "Hundred"]
def getNum_Words(number, index):
length = len(number)
if length > 3:
return False
number = number.zfill(3)
string = ""
hundreds_digit = ord(number[0]) - 48
tens_digit = ord(number[1]) - 48
ones_digit = ord(number[2]) - 48
string += "" if number[0] == '0' else ones[hundreds_digit]
string += " Hundred " if not string == "" else ""
if tens_digit > 1:
string += tens[tens_digit - 2]
string += " "
string += ones[ones_digit]
elif tens_digit == 1:
string += after_ten[(int(tens_digit + ones_digit) % 10) - 1]
elif tens_digit == 0:
string += ones[ones_digit]
if string.endswith("Zero"):
string = string[:-len("Zero")]
else:
string += ""
if not len(string) == 0:
string += suffixes[index]
return string
def initiateProcess(number):
while True:
length = len(str(number))
counter = int(length / 3) if length % 3 == 0 else int(length / 3) + 1
counter_copy = counter
word_representation = []
for i in range(length - 1, -1, -3):
word_representation.append(
getNum_Words(str(number)[0 if i - 2 < 0 else i - 2: i + 1], counter_copy - counter))
counter -= 1
print("Number in Words: ", end="", flush=True)
for s in reversed(word_representation):
if not len(s.strip()) == 0:
print(s + " ", end="", flush=True)
return ""
print("*=" * 50)
print("Input should be in this format to continue: [PHP/VND/USD] [123,456,789.90]")
print("Final input should be in this format: eg. [PHP 123,456,789.90]")
print("*=" * 50)
print()
while True:
numValue = str(input("Enter your desired Value: "))
if "-" in numValue:
print("Value out of Range. Please Try again.")
print("[Value should not be greater than 1,000,000,000,000.99 and not less than 0.01]")
break
else:
numValue = str(numValue.replace(',', ''))
numValue = numValue + ".00"
res1 = "".join(re.split("[^a-zA-Z]*", numValue))
temp = re.findall("\d+\.\d+", numValue)
res = list(map(float, temp))
number = []
moneyCurrency = ["PHP","VND","USD"]
currencyMoney = str(res1)
currencyValue = float(''.join(map(str, res)))
integerPart = int(currencyValue)
decimalPart = (float(currencyValue) - int(currencyValue))
number.append(integerPart)
decimalPart = (round(decimalPart, 2)) * 100
print()
if (currencyMoney in moneyCurrency) and (currencyValue <= 1000000000000.99):
if ((integerPart >= 1) and (decimalPart >= 0.01)) == True:
if 1 <= decimalPart < 10:
print("*=" * 50)
print(initiateProcess(integerPart) + currencyMoney, "and", ones[int(decimalPart)] + " Cents")
print("*=" * 50)
elif 10 <= decimalPart < 20:
print("*=" * 50)
print(initiateProcess(integerPart) + currencyMoney, "and", after_ten[int(decimalPart) - 10] + " Cents")
print("*=" * 50)
elif 20 <= decimalPart < 100:
centsA = (int(decimalPart) // 10)
centsB = (int(decimalPart) % 10)
print("*=" * 50)
print(initiateProcess(integerPart) + currencyMoney, "and", tens[centsA - 2], cents[centsB] + " Cents")
print("*=" * 50)
else:
print("*=" * 50)
print(initiateProcess(integerPart) + currencyMoney, "and", "Zero Cents")
print("*=" * 50)
elif ((integerPart >= 1) and (decimalPart == 0)) == True:
print("*=" * 50)
print(initiateProcess(integerPart) + currencyMoney, "and", "Zero Cents")
print("*=" * 50)
elif ((integerPart == 0) and (decimalPart >= 0.01)) == True:
if 1 <= decimalPart < 10:
print("*=" * 50)
print("Number in Words: ", currencyMoney, ones[int(decimalPart)] + " Cents")
print("*=" * 50)
elif 10 <= decimalPart < 20:
print("*=" * 50)
print("Number in Words: ", currencyMoney, after_ten[int(decimalPart) - 10] + " Cents")
print("*=" * 50)
elif 20 <= decimalPart < 100:
centsA = (int(decimalPart) // 10)
centsB = (int(decimalPart) % 10)
print("*=" * 50)
print("Number in Words: ", currencyMoney, tens[centsA - 2], cents[centsB] + " Cents")
print("*=" * 50)
else:
print("*=" * 50)
print("Value out of Range. Please Try again.")
print("[Value should not be greater than 1,000,000,000,000.99 and not less than 0.01]")
print("*=" * 50)
else:
print("*=" * 50)
print("Value out of Range. Please Try again.")
print("[Value should not be greater than 1,000,000,000,000.99 and not less than 0.01]")
print("*=" * 50)
else:
print("*=" * 50)
print("Invalid Currency or Value Exceeded Maximum Threshold. Please Try again.")
print("*=" * 50)
break