Exercices for Variables
Exercise Set 1: Variable Basics
-
Name Game Write a program that:
- Creates variables for first name, last name, and age
- Follows Python naming conventions (snake_case)
- Prints all variables
- Includes comments explaining your naming choices
-
Variable Swap Create a program that:
- Creates two variables with different values
- Swaps their values
- Prints the values before and after swapping
Exercise Set 2: Variable Naming Rules
-
Identify Valid Names Look at these variable names and comment which are valid and which are invalid:
# Add comments to explain why each is valid or invalid
first_name = "John"
1st_name = "John"
firstName = "John"
first-name = "John"
_first_name = "John"
first name = "John" -
Fix Bad Names Improve these variable names according to Python conventions:
x = "John Smith"
a = 25
thing = "Developer"
DATA = True
Exercise Set 3: Variable Reassignment
- Value Tracking
Write a program that:
- Creates a variable called
counter
- Assigns it different values five times
- Prints the value after each assignment
- Comments showing what you expect the output to be
- Creates a variable called