Quick actions

cmd+k|ctrl+k

Navigation

Languages

Closure - App

Snippet info

Language

Python

Visibility

public

Author

tendycode

Created

2025-06-24T01:21:17.281015Z

Updated

2025-06-24T01:32:23.367667Z

def sales_tax_calculator(tax_rate_percent):
    """Returns a closure that calculates total coast including"""
    def calculate(amount):
        return amount * (1 + tax_rate_percent / 100)
    return calculate
    
# Example usage:
calculate_ny_tax = sales_tax_calculator(8.875) # NY tax rate : 
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}")

# line 1 to 5 is only for register variables and the calculation is in line 12-13
INFO