Right now every time I use cost = get_cost(), for instance, the function goes through and asks for an input again. Is there a way to have just the return value be what is saved, so I can use that value in another function? Thanks for all the help.
def get_cost():
cost = float(input('Please Enter the Cost of the Meal: '))
while cost <= 0:
print('The Cost Must Be Greater Than 0!')
cost = float(input('Please Enter the Cost of the Meal: '))
else:
return cost
def compute_tip():
cost = get_cost()
finalTip = cost * 0.18
return finalTip
def compute_tax():
cost = get_cost()
finalTax = cost * 0.0825
return finalTax
def compute_grand_total():
cost = get_cost()
finalTip = compute_tip()
finalTax = compute_tax()
grandTotal = cost + finalTip + finalTax
return grandTotal
def display_total_cost():
cost = get_cost()
finalTip = compute_tip()
finalTax = compute_tax()
grandTotal = compute_grand_total()
print('Cost\t$', format(cost, '.2f'))
print('Tip\t$', format(finalTip, '.2f'))
print('Tax\t$', format(finalTax, '.2f'))
print('Total\t$', format(grandTotal, '.2f'))
def main():
get_cost()
compute_tip()
compute_tax()
compute_grand_total()
display_total_cost()
main()