Quick actions

cmd+k|ctrl+k

Navigation

Languages

Inner function closure 3 (應用)

Snippet info

Language

Python

Visibility

public

Author

kachuntong01

Created

2025-06-24T01:18:21.935315Z

Updated

2025-06-24T01:39:26.973304Z

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}")
INFO