Lesson guide
What this Python exercise practices
Define a Variable is a beginner practice lesson that focuses on functions, parameters, return values. It is designed to be solved in about 6 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- Function parameters
- Return values
Difficulty and time
- Level
- Beginner
- Estimated time
- 6 minutes
Practice path
Related public exercises
Summary
Learn how to assign a value to a variable and return it.
Problem statement
Implement the function define_variable(value). Inside the function, assign the input value to a variable named x and return x. This exercise practices the simplest form of storing data in a variable and returning it from a function.
Task
Write a function that assigns the input value to a variable and returns it, reinforcing basic variable assignment.
Examples
Store and return a number
Input
define_variable(5)
Output
5
Explanation
Assign 5 to x and return it; the returned value is the number 5.
Input format
A single argument passed to the function define_variable(value). The argument may be any Python value (number, string, boolean, etc.).
Output format
Return the same value that was passed in. The test harness compares str(returned_value) to the expected output.
Constraints
You must assign the input to a variable named x and return x. Do not print anything. The function should accept and return any value type.
Samples
Sample input 0
define_variable('hello')
Sample output 0
hello
Explanation 0
The string 'hello' is stored in x and returned.
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.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.