Inner function closure 3 (應用)

Run Settings
LanguagePython
Language Version
Run Command
def sales_tax_calculator(tax_rate_percent): # tax_reate_percent = 8.87 """Returns a closure that calculates total cost including""" def calculate(amount): return amount * (1 + tax_rate_percent / 100) return calculate # Example usage: calculate_ny_tax = sales_tax_calculator (8.875) calculate_ca_tax = sales_tax_calculator (7.25) #Calculate totals ny_total = calculate_ny_tax(100.0) ca_total = calculate_ca_tax(100.0) print(f"NY Total (${100} + tax): ${ny_total:.2f}") print(f"CA Total (${100} + tax): ${ca_total:.2f}")
Editor Settings
Theme
Key bindings
Full width
Lines