#1
01.01.2021 um 21:24 UhrWenn man einen negativen Hubraum eingibt, wird dafür ein negativer Steueranteil berechnet.
Python :: Aufgabe #310 :: Lösung #2
import math
from functools import lru_cache
from typing import Literal
# to prevent wrong parameters
# pip install strongtyping
from strongtyping.strong_typing import match_typing
# Config dict for price per started 100 cc
pp_ccm = {
'Otto': 2.00,
'Diesel': 9.50
}
# Config dict for co2 price in different sectors
price_co2 = {
(96, 115): 2.00,
(116, 135): 2.20,
(136, 155): 2.50,
(156, 175): 2.90,
(176, 195): 3.40,
(195, -1): 4.00, # -1 used as no upper limit
}
@lru_cache
@match_typing
def calc_kfz_tax(kfz_type: Literal['Diesel', 'Otto'], ccm: int, co2_g: int) -> float:
"""
:return: total tax for a year in Euro
"""
price_cc = math.ceil(ccm / 100) * pp_ccm[kfz_type]
if co2_g <= 95:
total_tax = price_cc
elif co2_g > 195:
total_co2 = sum(((k[1] - k[0]) + 1) * v
if k[0] < 195
else
(co2_g - k[0]) * v
for k, v in price_co2.items())
total_tax = price_cc + total_co2
else:
total_co2 = 0
for k, v in price_co2.items():
if co2_g <= k[1]:
total_co2 += ((co2_g - k[0]) + 1) * v
break
elif k[1] < co2_g:
total_co2 += ((k[1] - k[0]) + 1) * v
total_tax = price_cc + total_co2
return total_tax
Kommentare:
Gelöschte Person
Punkte: 0
2 Kommentare
felixTheC
Punkte: 1200
23 Lösungen
4 Kommentare