|
|
发表于 2018-3-2 09:18:14
|
显示全部楼层
- incoming_tax = {
- (0,1500) : 0.03,
- (1500,4500) : 0.1,
- (4500,9000) : 0.2,
- (9000,35000) : 0.25,
- (35000,55000) : 0.3,
- (55000,80000) : 0.35
- }
- incoming = int(input("Input your incoming:"))
- for_tax = incoming - 3500
- if for_tax < 0:
- print("No need to tax")
- else:
- total_tax = 0
- while for_tax > 0:
- for tax in incoming_tax:
- if tax[0]<for_tax<=tax[1]:
- tmp = for_tax - tax[0]
- for_tax = tax[0]
- total_tax += tmp*incoming_tax[tax]
- break
- print("Your incoming: %d needs to pay %.2f for tax" % (incoming, total_tax))
复制代码
代码要简洁易懂,尽量减少用if,看着累,修改也不方便。 |
|