Python – Variable Exercises
Exercise 1: Create a Variable and Print It
Question
Create a variable called name and store your name.
Print the value.
Solution
Exercise 2: Store a Number and Print It
Question
Create a variable age and store your age.
Print it.
Solution
Exercise 3: Print Text with Variable
Question
Store your city in a variable and print a sentence.
Solution
Exercise 4: Add Two Numbers Using Variables
Question
Create two variables and print their sum.
Solution
Exercise 5: Change Variable Value
Question
Create a variable and change its value.
Solution
Exercise 6: Assign Multiple Values
Question
Assign values to three variables in one line and print them.
Solution
Exercise 7: Same Value to Multiple Variables
Question
Assign the same value to three variables.
Solution
Exercise 8: Take Input and Store in Variable
Question
Ask user for name and print it.
Solution
Exercise 9: Take Number Input and Add 1
Question
Ask user for age and print next year age.
Solution
Exercise 10: Swap Two Variables
Question
Swap two numbers using variables.
Solution
Exercise 11: Print Variable Type
Question
Create a variable and print its type.
Solution
Exercise 12: Simple Real-Life Example
Question
Store product name and price, then print them.
Solution
Exercise 13: Fix the Error
Question
Fix the error in the code.
❌ Wrong code:
Correct Code
Exercise 14: Global Variable Example
Question
Create a global variable and print it inside a function.
Solution
Exercise 15: Update Variable Using Itself
Question
Increase a number by 1.
Solution
✅ Summary
✔ Variables store data
✔ Values can change
✔ Input can be stored
✔ Multiple assignment is possible
✔ Practice makes perfect
📘 Perfect for Beginner eBook
This exercise chapter is perfect for:
-
Python beginner books
-
School & college students
-
Self-learners
If you want next, I can write:
-
Data Type Exercises
-
Input & Output Exercises
-
if–else Practice
-
Loop Exercises
-
MCQs with answers
Just tell me 😊
