Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 11

Define a function that reads a global variable

Easy

7 minute session

Summary

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

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

Explanation

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 input 0

apply_tax(50.5)

Sample output 0

55.55

Explanation 0

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

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

09:04 PM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.