status=int(input("請選擇你的身份:1 納稅人:\n"))
income=int(input("輸入你的收入:"))
tax=0if status==1:
if income<=8350:tax=income*0.1
elif
income<=33950:tax=8350*0.1+(income-8350)*0.15
elif
income<=82250:tax=8350*0.1+(33950-8350)*0.15+(income-33950)*0.25
elif income<=171550:tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(income-171550)*0.28
elif income<=372950:tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(income-372950)*0.33
elif income>=372950:tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(372950-171550)*0.33+(income-372950)*0.35
print("應繳納的稅費為:",tax)
如何為這段代碼添加輸入錯誤提示。意思就是說不輸入1就會出現錯誤提示(這是一個計算稅費的)
uj5u.com熱心網友回復:
參考 1 樓 lanzhen001的回復:
status=int(input("請選擇你的身份:1 納稅人:\n"))
n = 0
while status !=1 and n<10: #計數,輸入錯誤超過10次就退出
print('輸入錯誤')
status=int(input("請選擇你的身份:1 納稅人:\n"))
n+=1
if status ==1:
income=int(input("輸入你的收入:"))
if income<=8350:
tax=income*0.1
elif income<=33950:
tax=8350*0.1+(income-8350)*0.15
elif income<=82250:
tax=8350*0.1+(33950-8350)*0.15+(income-33950)*0.25
elif income<=171550:
tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(income-171550)*0.28
elif income<=372950:
tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(income-372950)*0.33
elif income>=372950:
tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(372950-171550)*0.33+(income-372950)*0.35
print("應繳納的稅費為:",tax)
那大佬問一下啊
uj5u.com熱心網友回復:
參考 1 樓 lanzhen001的回復:
status=int(input("請選擇你的身份:1 納稅人:\n"))
n = 0
while status !=1 and n<10: #計數,輸入錯誤超過10次就退出
print('輸入錯誤')
status=int(input("請選擇你的身份:1 納稅人:\n"))
n+=1
if status ==1:
income=int(input("輸入你的收入:"))
if income<=8350:
tax=income*0.1
elif income<=33950:
tax=8350*0.1+(income-8350)*0.15
elif income<=82250:
tax=8350*0.1+(33950-8350)*0.15+(income-33950)*0.25
elif income<=171550:
tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(income-171550)*0.28
elif income<=372950:
tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(income-372950)*0.33
elif income>=372950:
tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(372950-171550)*0.33+(income-372950)*0.35
print("應繳納的稅費為:",tax)
那這個呢?這個有四個選項?
status=int(input("請選擇你的身份:1 單身納稅人,2 已婚合并申報人,3 已婚分開申報人,4 戶住:\n"))income=int(input("輸入你的收入:"))tax=0if status==1:if income<=8350:tax=income*0.1elif income<=33950:tax=8350*0.1+(income-8350)*0.15elif income<=82250:tax=8350*0.1+(33950-8350)*0.15+(income-33950)*0.25elif income<=171550:tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(income-171550)*0.28elif income<=372950:tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(income-372950)*0.33elif income>=372950:tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(372950-171550)*0.33+(income-372950)*0.35if status==2:if income<=16700:tax=income*0.1elif income<=67900:tax=16700*0.1+(income-16700)*0.15elif income<=137050:tax=16700*0.1+(67900-16700)*0.15+(income-67900)*0.25elif income<=208850:tax=16700*0.1+(67900-16700)*0.15+(137050-67900)*0.25+(income-137050)*0.28elif income<=372950:tax=16700*0.1+(67900-16700)*0.15+(137050-67900)*0.25+(208850-137050)*0.28+(income-208850)*0.33elif income>=372950:tax=16700*0.1+(67900-16700)*0.15+(137050-67900)*0.25+(208850-137050)*0.28+(372950-208850)*0.33+(income-372950)*0.35if status==3:if income<=8350:tax=income*0.1elif income<=33950:tax=8350*0.1+(income-8350)*0.15elif income<=68525:tax=8350*0.1+(33950-8350)*0.15+(income-33950)*0.25elif income<=104425:tax=8350*0.1+(33950-8350)*0.15+(68525-33950)*0.25+(income-68525)*0.28elif income<=186475:tax=8350*0.1+(33950-8350)*0.15+(68525-33950)*0.25+(104425-68525)*0.28+(income-104425)*0.33elif income>=186475:tax=8350*0.1+(33950-8350)*0.15+(68525-33950)*0.25+(104425-68525)*0.28+(186475-104425)*0.33+(income-186475)*0.35if status==4:if income<=11950:tax=income*0.1elif income<=45500:tax=11950*0.1+(income-11950)*0.15elif income<=117450:tax=11950*0.1+(45500-11950)*0.15+(income-45500)*0.25elif income<=190200:tax=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(income-117450)*0.28elif income<=372950:tax=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(190200-117450)*0.28+(income-190200)*0.33elif income>=372950:tax=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(190200-117450)*0.28+(372950-190200)*0.33+(income-372950)*0.35print("應繳納的稅費為:",tax)
uj5u.com熱心網友回復:
參考 5 樓 lanzhen001的回復: 其他更簡便的方法你可以自己嘗試,我這里不是最優的。
def bachelordom(income):
if income<=8350:
tax=income*0.1
elif income<=33950:
tax=8350*0.1+(income-8350)*0.15
elif income<=82250:
tax=8350*0.1+(33950-8350)*0.15+(income-33950)*0.25
elif income<=171550:
tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(income-171550)*0.28
elif income<=372950:
tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(income-372950)*0.33
elif income>=372950:
tax=8350*0.1+(33950-8350)*0.15+(82250-33950)*0.25+(171550-82250)*0.28+(372950-171550)*0.33+(income-372950)*0.35
return tax
def married_and(income):
if income<=16700:
tax=income*0.1
elif income<=67900:
tax=16700*0.1+(income-16700)*0.15
elif income<=137050:
tax=16700*0.1+(67900-16700)*0.15+(income-67900)*0.25
elif income<=208850:
tax=16700*0.1+(67900-16700)*0.15+(137050-67900)*0.25+(income-137050)*0.28
elif income<=372950:
tax=16700*0.1+(67900-16700)*0.15+(137050-67900)*0.25+(208850-137050)*0.28+(income-208850)*0.33
elif income>=372950:
tax=16700*0.1+(67900-16700)*0.15+(137050-67900)*0.25+(208850-137050)*0.28+(372950-208850)*0.33+(income-372950)*0.35
return tax
def married_out(income):
if income<=8350:
tax=income*0.1
elif income<=33950:
tax=8350*0.1+(income-8350)*0.15
elif income<=68525:
tax=8350*0.1+(33950-8350)*0.15+(income-33950)*0.25
elif income<=104425:
tax=8350*0.1+(33950-8350)*0.15+(68525-33950)*0.25+(income-68525)*0.28
elif income<=186475:
tax=8350*0.1+(33950-8350)*0.15+(68525-33950)*0.25+(104425-68525)*0.28+(income-104425)*0.33
elif income>=186475:
tax=8350*0.1+(33950-8350)*0.15+(68525-33950)*0.25+(104425-68525)*0.28+(186475-104425)*0.33+(income-186475)*0.35
return tax
def header(income):
if income<=11950:
tax=income*0.1
elif income<=45500:
tax=11950*0.1+(income-11950)*0.15
elif income<=117450:
tax=11950*0.1+(45500-11950)*0.15+(income-45500)*0.25
elif income<=190200:
tax=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(income-117450)*0.28
elif income<=372950:
tax=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(190200-117450)*0.28+(income-190200)*0.33
elif income>=372950:
tax=11950*0.1+(45500-11950)*0.15+(117450-45500)*0.25+(190200-117450)*0.28+(372950-190200)*0.33+(income-372950)*0.35
return tax
if __name__ == '__main__':
anss = True
n = 0
while anss and n<10:
status=input("請選擇你的身份:1 單身納稅人,2 已婚合并申報人,3 已婚分開申報人,4 戶住:\n")
ls = str(range(1,5))
if status in ls:
income=int(input("輸入你的收入:"))
dic = {'1':bachelordom(income),'2':married_and(income),'3':married_out(income),'4':header(income)}
tax = dic[status]
print(f'應繳納的稅費為:{tax:.2f}')
anss = False
else:
print('你的輸入有誤,請重試!')
n+=1
你這個我運行不了啊
uj5u.com熱心網友回復:
繼續壓縮代碼。。。。
def math_s(income,a,b,c,d,e):
if income<=a:
tax=income*0.1
elif income<=b:
tax=a*0.1+(income-a)*0.15
elif income<=c:
tax=a*0.1+(b-a)*0.15+(income-b)*0.25
elif income<=d:
tax=a*0.1+(b-a)*0.15+(c-b)*0.25+(income-d)*0.28
elif income<=e:
tax=a*0.1+(b-a)*0.15+(c-b)*0.25+(d-c)*0.28+(income-e)*0.33
elif income>=e:
tax=a*0.1+(b-a)*0.15+(c-b)*0.25+(d-c)*0.28+(e-d)*0.33+(income-e)*0.35
return tax
if __name__ == '__main__':
anss = True
n = 0
while anss and n<10:
status=input("請選擇你的身份:1 單身納稅人,2 已婚合并申報人,3 已婚分開申報人,4 戶住:\n")
ls = ['1','2','3','4']
if status in ls:
income=int(input("輸入你的收入:"))
dic = {
'1':math_s(income,8350,33950,82250,171550,372950),
'2':math_s(income,16700,67900,137050,208850,372950),
'3':math_s(income,8350,33950,68525,104425,186475),
'4':math_s(income,11950,45500,117450,190200,372950)
}
tax = dic[status]
print(f'應繳納的稅費為:{tax:.2f}')
anss = False
else:
print('你的輸入有誤,請重試!')
n+=1
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/38549.html
標籤:腳本語言(Perl/Python)
上一篇:火柴人游戲出現報錯:invalid command name ".!canvas",請教大神應該怎么修正?
下一篇:[求助]關于模塊scipy中的curve_fit函式的用法