Jill P. answered 03/11/23
Computer Science Professional
def calculate_electricity_bill():
# Read in user input for monthly consumption and market price of electricity
consumption = float(input("Enter monthly consumption (in kilowatt hours): "))
price = float(input("Enter market price of electricity (in øre per kilowatt hour): "))
# Calculate the amount that exceeds 70 øre per kWt
excess = max(0, consumption - 5000) * price * 0.1 if price > 70 else 0
# Calculate the subsidy and the amount to be paid by the customer
subsidy = min(consumption, 5000) * max(0, 70 - price) * 0.9
payment = (consumption - min(consumption, 5000)) * price + excess
# Display the results to the user
print("Subsidy: {:.2f} kr".format(subsidy / 100))
print("Payment: {:.2f} kr".format(payment / 100))
# Keep asking the user if they want to calculate another bill
while True:
calculate_electricity_bill()
choice = input("Do you want to calculate another bill? (y/n)").lower()
if choice != 'y':
break
The program prompts the user to enter the monthly consumption and the market price of electricity, then calculates the subsidy and payment using the given formula. It then displays the results to the user and asks if they want to calculate another bill. The program will continue to run until the user chooses to stop.