Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DISCOUNTS = [0.25, 0.30]
- THRESHOLDS = [100, 200]
- # Questa funzione accetta in input una variabile numerica e
- # ne ritorna lo sconto.
- # Tipo di variable supportati:
- # - int (es: 4)
- # - float (es: 5.34)
- # - string (es: "100000")
- def get_discounted_price(price):
- # if int or float
- if type(price) is int or type(price) is float:
- # se <= 99
- if price < THRESHOLDS[0]:
- print("No discount for you")
- return price
- # 100 < prezzo < 199
- elif price >= THRESHOLDS[0] and price < THRESHOLDS[1]:
- final_price = price - price * DISCOUNTS[0]
- return final_price
- # prezzo > 199
- else:
- final_price = price - price * DISCOUNTS[1]
- return final_price
- else:
- # if string, try to cast it
- try:
- casted_price = float(price)
- final_price = get_discounted_price(casted_price)
- return final_price
- except:
- print("Only numbers are supported")
- initial_price = "11000"
- final_price = get_discounted_price(initial_price)
- print(str(final_price) + "$")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement