Chapter 2: Getting Started with Python
2.4 Practical Exercises for Chapter 2: Getting Started with Python
Exercise 1: Install Python
If you haven't already, follow the instructions in Section 2.1 to install Python on your computer. Verify the installation by running python --version
(Windows) or python3 --version
(Mac/Linux) in your terminal.
Exercise 2: Your First Python Script
Create a Python script named hello.py
and write code to print "Hello, world!" when run. Execute the script from your terminal.
# Expected Output
Hello, world!
Exercise 3: Working with Variables
- Create a variable named
name
and assign it your name as a string. - Create a variable named
age
and assign it your age as an integer. - Print a sentence using these variables like: "My name is [Your Name], and I am [Your Age] years old."
Exercise 4: Type Conversion
- Create a string variable
string_number
with the value"25"
. - Convert this string into an integer and store it in a new variable
integer_number
. - Multiply
integer_number
by 4 and print the result.
Exercise 5: Explore Data Types
- Create a list named
fruits
with some of your favorite fruits. - Create a boolean variable
is_student
and set it to either True or False based on your current student status. - Print all these variables and their types using
print()
andtype()
.
Example:
print(fruits, type(fruits))
print(is_student, type(is_student))
Exercise 6: Variable Naming
Create variables following the best practices described in Section 2.3. Store different types of data in them and print them out. Avoid using Python's reserved words for your variable names.
2.4 Practical Exercises for Chapter 2: Getting Started with Python
Exercise 1: Install Python
If you haven't already, follow the instructions in Section 2.1 to install Python on your computer. Verify the installation by running python --version
(Windows) or python3 --version
(Mac/Linux) in your terminal.
Exercise 2: Your First Python Script
Create a Python script named hello.py
and write code to print "Hello, world!" when run. Execute the script from your terminal.
# Expected Output
Hello, world!
Exercise 3: Working with Variables
- Create a variable named
name
and assign it your name as a string. - Create a variable named
age
and assign it your age as an integer. - Print a sentence using these variables like: "My name is [Your Name], and I am [Your Age] years old."
Exercise 4: Type Conversion
- Create a string variable
string_number
with the value"25"
. - Convert this string into an integer and store it in a new variable
integer_number
. - Multiply
integer_number
by 4 and print the result.
Exercise 5: Explore Data Types
- Create a list named
fruits
with some of your favorite fruits. - Create a boolean variable
is_student
and set it to either True or False based on your current student status. - Print all these variables and their types using
print()
andtype()
.
Example:
print(fruits, type(fruits))
print(is_student, type(is_student))
Exercise 6: Variable Naming
Create variables following the best practices described in Section 2.3. Store different types of data in them and print them out. Avoid using Python's reserved words for your variable names.
2.4 Practical Exercises for Chapter 2: Getting Started with Python
Exercise 1: Install Python
If you haven't already, follow the instructions in Section 2.1 to install Python on your computer. Verify the installation by running python --version
(Windows) or python3 --version
(Mac/Linux) in your terminal.
Exercise 2: Your First Python Script
Create a Python script named hello.py
and write code to print "Hello, world!" when run. Execute the script from your terminal.
# Expected Output
Hello, world!
Exercise 3: Working with Variables
- Create a variable named
name
and assign it your name as a string. - Create a variable named
age
and assign it your age as an integer. - Print a sentence using these variables like: "My name is [Your Name], and I am [Your Age] years old."
Exercise 4: Type Conversion
- Create a string variable
string_number
with the value"25"
. - Convert this string into an integer and store it in a new variable
integer_number
. - Multiply
integer_number
by 4 and print the result.
Exercise 5: Explore Data Types
- Create a list named
fruits
with some of your favorite fruits. - Create a boolean variable
is_student
and set it to either True or False based on your current student status. - Print all these variables and their types using
print()
andtype()
.
Example:
print(fruits, type(fruits))
print(is_student, type(is_student))
Exercise 6: Variable Naming
Create variables following the best practices described in Section 2.3. Store different types of data in them and print them out. Avoid using Python's reserved words for your variable names.
2.4 Practical Exercises for Chapter 2: Getting Started with Python
Exercise 1: Install Python
If you haven't already, follow the instructions in Section 2.1 to install Python on your computer. Verify the installation by running python --version
(Windows) or python3 --version
(Mac/Linux) in your terminal.
Exercise 2: Your First Python Script
Create a Python script named hello.py
and write code to print "Hello, world!" when run. Execute the script from your terminal.
# Expected Output
Hello, world!
Exercise 3: Working with Variables
- Create a variable named
name
and assign it your name as a string. - Create a variable named
age
and assign it your age as an integer. - Print a sentence using these variables like: "My name is [Your Name], and I am [Your Age] years old."
Exercise 4: Type Conversion
- Create a string variable
string_number
with the value"25"
. - Convert this string into an integer and store it in a new variable
integer_number
. - Multiply
integer_number
by 4 and print the result.
Exercise 5: Explore Data Types
- Create a list named
fruits
with some of your favorite fruits. - Create a boolean variable
is_student
and set it to either True or False based on your current student status. - Print all these variables and their types using
print()
andtype()
.
Example:
print(fruits, type(fruits))
print(is_student, type(is_student))
Exercise 6: Variable Naming
Create variables following the best practices described in Section 2.3. Store different types of data in them and print them out. Avoid using Python's reserved words for your variable names.