Practical Exercises for Chapter 2
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...