

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


def calculate_tax(price, rate=0.20): # Arguments (with 1 default) tax_amount = price * rate # Local Scope variable return tax_amount # Output result final_tax = calculate_tax( 100 ) # Calls function
rate = 0. def tax(price): return price * rate # Relies heavily on outside variables
- Use (Self-Contained Pure Functions): def tax(price, rate): return price * rate # Pass inputs directly into arguments
Understand what the error tells us - (remember errors are our friends): Error Message Typical Cause Instant Fix NameError: name 'tax_amount' is not defined Trying to use a local variable outside its parent function block. Either print it inside the function or return the value to a global variable. TypeError: missing required positional argument Calling a function without passing the required number of inputs. Provide all missing values inside the parentheses when running the function.