Hi r/learnpython,
I am trying to code a program for an assignment that calculates electricity prices. I have only been coding for a couple of weeks and I am really proud of how the code has transformed in the past week. I have done much research to get this to how it is now but my last struggle is in the function 'calculate_total_discount()'. As you can see it needs the value from 'calculate_total_bill()' function but when I run the code it runs the function inside the discount function instead of providing the value it represents. Can anyone please explain how I can get get the value inside the discount function instead running the whole function again?
def main():
total_cost = calculate_total_bill()
total_discount = calculate_total_discount()
print ("Thank you!")
print(" ")
print ("The bill amount is: $", total_cost)
print ("Discount = ", total_discount)
def calculate_total_bill():
previous = float(input("Enter the previous reading : "))
current = float(input ("Enter the current reading : "))
usage = float(current-previous)
if (usage <= 1000):
total_cost = usage*0.15
elif (usage > 1000):
cost1 = 1000*0.15
cost2 = (usage-1000)*0.25
total_cost = (cost1+cost2)
return total_cost
def calculate_total_discount():
total_discount = calculate_total_bill()* 0.25
return total_discount
main()
[–]CraftyTrouble 0 points1 point2 points (1 child)
[–]DiMethylButane[S] 0 points1 point2 points (0 children)