The questions asks us to create a Python program that asks the user to input the number of cars, the parking duration and parking fee and calculate its total fees and total average. I'm able to find everything I need EXCEPT the total average.
sum = 0.00
fee = 0
avg = 0
x = int(input("Number of cars:"))
while x > 0:
y = float(input("Duration of parking:"))
if y <= 3:
fee = 2
print("Fee: 2")
elif 3 < y <= 23
fee = 2 + (0.05 * y)
elif y == 24:
fee = 10
print("Fee: 10")
x = x - 1
sum = sum + fee
avg = sum / x
print("Total fees:", sum)
print("Average:")
This is my code and the only problem is the average. It gives me a 'ZeroDivisionError: float division zero' for my 'avg = sum / x' so it's basically saying my x is zero and I have no idea why or how to solve it. I've tried almost everything. Please help.
x=x-1to after you calculate the avg.sumkeyword. 2. Please use a dictionary for the fees or somethings else, but not a super longif...else, it's bad code.