6.1.2 Returning Values: The return Statement

Unit: Unit 6: Functions • Interactive Practice

Quick Answer & Summary:

Interactive Python programming tutorial and practice in your browser.

Interactive Challenge (Run Live in Browser):

# Define functions that compute and return values
def calculate_tax(subtotal, tax_rate):
    tax_amount = subtotal * tax_rate
    return round(tax_amount, 2)

def calculate_total(subtotal, tax_rate):
    tax = calculate_tax(subtotal, tax_rate)
    return subtotal + tax

order_subtotal = 120.00
rate = 0.08

tax = calculate_tax(order_subtotal, rate)
final_total = calculate_total(order_subtotal, rate)

print("Tax:", tax)
print("Final Total:", final_total)
Open in Live Interactive Python Sandbox →