Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Define a function that reads a global variable

Use a module-level global variable inside a function to compute a result.

Python practice7 minFunctions & ScopeBeginnerLast updated March 17, 2026

Problem statement

There is a module-level global variable TAX_RATE representing a tax rate (for example 0.10 for 10%). Define a function apply_tax(price) that reads the global TAX_RATE and returns the price after applying tax (price + price * TAX_RATE). Do not reassign TAX_RATE inside the function — only read its value.

Task

Implement a function that reads a global constant (TAX_RATE) and applies it to an input value.

Examples

Apply 10% tax to 100

Input

apply_tax(100)

Output

110.0

With TAX_RATE = 0.1, 100 + 100 * 0.1 = 110.0.

Input format

A numeric price (int or float). The TAX_RATE global variable is defined in the module.

Output format

A numeric result (float) representing the price after tax.

Constraints

Read the global TAX_RATE variable; do not try to re-declare it inside the function. Support integer and float inputs.

Samples

Sample 1

Input

apply_tax(50.5)

Output

55.55

50.5 + 50.5 * 0.1 = 55.55 (with TAX_RATE = 0.1).