我在下面写了这个脚本,它将数字转换为它的拼写。
no = raw_input("Enter a number: ")
strcheck = str(no)
try:
val = int(no)
except ValueError:
print("sayi degil")
raise SystemExit
lencheck = str(no)
if len(lencheck) > 6:
print("Bu sayi cok buyuk !")
raise SystemExit
n = int(no)
print(n)
def int2word(n):
n3 = []
r1 = ""
ns = str(n)
for k in range(3, 33, 3):
r = ns[-k:]
q = len(ns) - k
if q < -2:
break
else:
if q >= 0:
n3.append(int(r[:3]))
elif q >= -1:
n3.append(int(r[:2]))
elif q >= -2:
n3.append(int(r[:1]))
r1 = r
#print(n3)
nw = ""
for i, x in enumerate(n3):
b1 = x % 10
b2 = (x % 100)//10
b3 = (x % 1000)//100
if x == 0:
continue
else:
t = binler[i]
if b2 == 0:
nw = birler[b1] + t + nw
elif b2 == 1:
nw = onlar[1] + birler[b1] + t + nw
elif b2 > 1:
nw = onlar[b2] + birler[b1] + t + nw
if b3 > 0:
nw = birler[b3] + "yuz " + nw
return nw
birler = ["", " ","iki ","uc ","dort ", "bes ", "alti ","yedi ","sekiz ","dokuz "]
onlar = ["", "on ", "yirmi ", "otuz ", "kirk ", "elli ", "altmis ", "yetmis ", "seksen ", "doksan "]
binler = ["", "bin"]
print int2word(n)
该脚本在 Python2.7 上运行良好。
但是当我尝试用 python3.3 运行它时
它给了我以下错误:
File "numtospell.py", line 58
if x == 0:
^
TabError: inconsistent use of tabs and spaces in indentation
我已经用谷歌搜索了几个小时,但找不到合适的解决方案。我该怎么做才能解决这个问题?
谢谢你的帮助。