如果有人願意幫忙的話,我很感謝。我是初學者,
搞不太懂整個程式的結構和語法,最近在自學python,
如果有空的話,可以幫我個忙嗎下面這題
以if else if的結構,寫一個程式依照收入多寡繳納不同稅額的稅額。
54萬元以下免稅,大於54萬至121萬稅率12%,大於121萬至242萬稅率20%,
大於242萬至453萬稅率30%,大於453萬至1031萬稅率40%,
大於1031萬以上稅率45%。
tax = 0
if salary >= 540000 :
tax = 0.12
if salary >= 1210000 :
tax = 0.2
if salary >= 2420000:
tax = 0.3
if salary >= 4530000:
tax = 0.4
if salary >=10310000:
tax = 0.45
else : #這個ELSE有點脫褲子放屁了
tax = 0
def tax(mon):
if mon > 10310000:
return 0.45
elif mon <= 10310000 and mon > 4530000:
return 0.4
elif mon <= 4530000 and mon > 2420000:
return 0.3
elif mon <= 2420000 and mon > 1210000:
return 0.2
elif mon <= 1210000 and mon > 540000:
return 0.12
elif mon <= 540000 and mon >= 0:
return 0
elif mon < 0:
return "收入不得為負!"
else:
return "計算錯誤!"
def int_to_zh(mon):
if str(mon)[-2:] == ".0":
mon = str(mon)[:-2]
if type(mon) != "float":
mon = str(mon)
mon = mon[:-16]+mon[-16:].replace("0000000000000000", "京")
mon = mon[:-12]+mon[-12:].replace("000000000000", "兆")
mon = mon[:-8]+mon[-8:].replace("00000000", "億")
mon = mon[:-4]+mon[-4:].replace("0000", "萬")
return mon[:-3]+mon[-3:].replace("000", "千")
else:
return mon
mon = str(input("請輸入您的收入:"))
try:
mon = int(mon.replace("元", "").replace("百", "00").replace("千", "000").replace("萬", "0000").replace("十萬", "00000").replace("百萬", "000000").replace("千萬", "0000000").replace("億", "00000000").replace("十億", "000000000").replace("百億", "0000000000").replace("千億", "00000000000").replace("兆", "000000000000").replace("十兆", "0000000000000").replace("百兆", "00000000000000").replace("千兆", "000000000000000").replace("京", "0000000000000000"))
# print(mon)
except ValueError:
print("收入須為整數!")
exit()
try:
print("您的收入為"+int_to_zh(mon)+"元", "稅率為"+str(tax(mon)*100)[:-2]+"%", "稅額為"+int_to_zh(mon*tax(mon))+"元", "剩餘金額為"+int_to_zh(mon-mon*tax(mon))+"元", sep="|")
except:
print(tax(mon))
請輸入您的收入:453萬
您的收入為453萬元|稅率為30%|稅額為1359千元|剩餘金額為3171千元
code有點亂,對初學者來說功能有到即可?
這種東西網路上都有,國中生都會...