user16137775
user16137775

Reputation: 31

How do I calculate penalty fees incrementally in python?

I am trying to calculate penalty fees incrementally, the program must take the value of the first calculation and add it to the second and give total to be printed.

Here is my code:


if days >= 1 and days <= 4:
  payment = days * 3
  print("Payment is: ", "$", payment)
  
elif days >= 5 and days <= 10:
  payment = days * 5
  print("Payment is: ", "$", payment)

Upvotes: 2

Views: 672

Answers (2)

oreopot
oreopot

Reputation: 3450

My first instinct is to loop and maintain a count.

try the following solution:

change the range around since the values generated by range function starts from 0

total_penalty = 0
for i in range(total_delay):
    if i < 4:
        total_penalty += 3
    elif i >= 4 and i <= 9:
        total_penalty += 5  

print(total_penalty)

Upvotes: 4

pcbzmani
pcbzmani

Reputation: 27

I am assuming, actual amount and default days is given as input to this function.

def penalty(actual_amt,days):
    penalty_amt = 0
    if days == 0:
        print('No Penalty')
    elif days >=1 and days <=5:
        penalty_amt = actual_amt + ( days * 3 )
    elif days > 5 and days <=10:
        penalty_amt = actual_amt + ( days * 5 )
   
    print(f'Your total cost with penalty is {penalty_amt}') 
    return penalty_amt       

Upvotes: 0

Related Questions