Lab Activity: Variables, Data Types, and Basic Operations
Objectives
-
Understand how to declare and use variables in Python.
-
Identify and work with different data types.
-
Perform basic arithmetic operations.
-
Learn to take user input and process it in Python.
Lab Setup Instructions
-
Open your Python IDE (VS Code Editor).
-
Create a new Python file and name it:
lab_variables.py
step-by-step instructions:
Step 1: Declare and Print Variables
Instructions:
-
Declare variables to store your name, age, and a message about your interest in Python.
-
Print them using the
print()function.
Code Example:
name = "Python"
age = 30
interest = "I enjoy learning Python because it's useful for AI and automation."
print("Name:", name)
print("Age:", age)
print("Interest:", interest)
Step 2: Identify Data Types
Instructions:
-
Use the
type()function to print the data type of each variable.
Code Example:
print(type(name))
print(type(age))
print(type(interest))
Step 3: Perform Arithmetic Operations
Instructions:
-
Create two numeric variables
xandy. -
Perform addition, subtraction, multiplication, division, modulus, and exponentiation.
Code Example:
x = 10
y = 3
print("Sum:", x + y)
print("Difference:", x - y)
print("Product:", x * y)
print("Division:", x / y)
print("Modulus:", x % y)
print("Exponent:", x ** y)
Step 4: Take User Input
Instructions:
-
Ask the user to input their name and favorite number.
-
Display a greeting message.
-
Multiply the number by 2 and show the result.
Code Example:
user_name = input("Enter your name: ")
fav_number = int(input("Enter your favorite number: "))
print("Hi", user_name + "!")
print("Your number doubled is:", fav_number * 2)
