chore: added comments
This commit is contained in:
parent
1c2f806960
commit
25bc41726e
@ -30,11 +30,20 @@ D = {2: 10, 3: 100, 4: 1000, 5: 10000}
|
|||||||
|
|
||||||
|
|
||||||
def to_chinese_numeral(n):
|
def to_chinese_numeral(n):
|
||||||
|
# Check if n in C dictonary
|
||||||
try:
|
try:
|
||||||
return C[n]
|
return C[n]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Check if negative
|
||||||
|
if n < 0:
|
||||||
|
n = abs(n)
|
||||||
|
is_negative = True
|
||||||
|
else:
|
||||||
|
is_negative = False
|
||||||
|
|
||||||
|
# Put single digits in list
|
||||||
split_number = [int(x) for x in str(n)]
|
split_number = [int(x) for x in str(n)]
|
||||||
|
|
||||||
arranged_number = []
|
arranged_number = []
|
||||||
@ -46,7 +55,10 @@ def to_chinese_numeral(n):
|
|||||||
if arranged_number[-1] == 0:
|
if arranged_number[-1] == 0:
|
||||||
arranged_number.pop(-1)
|
arranged_number.pop(-1)
|
||||||
|
|
||||||
|
if is_negative:
|
||||||
|
arranged_number.append("-")
|
||||||
|
|
||||||
return arranged_number
|
return arranged_number
|
||||||
|
|
||||||
|
|
||||||
print(to_chinese_numeral(120))
|
print(to_chinese_numeral(-90909)) # 9 10000 9
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user