Hands-on examples provide practice with Python variables, data types (such as numbers and strings), operators, type conversion, and user input. These exercises involve creating small programs that perform calculations and interact with users.Example 1: A Simple Area CalculatorLet's create a script that calculates the area of a rectangle. It will ask the user for the length and width, perform the calculation, and display the result.Get Input: Ask the user for the length and width. Remember that the input() function returns text (a string).Convert Types: Convert the input strings to numbers (we'll use floating-point numbers to allow for decimals) using float().Calculate: Multiply the length by the width to get the area.Display Output: Print the result in a user-friendly format.# Get input for the length of the rectangle length_str = input("Enter the length of the rectangle: ") # Get input for the width of the rectangle width_str = input("Enter the width of the rectangle: ") # Convert the input strings to floating-point numbers length = float(length_str) width = float(width_str) # Calculate the area using the arithmetic multiplication operator area = length * width # Display the result using an f-string for formatted output print(f"The length is: {length}") print(f"The width is: {width}") print(f"The area of the rectangle is: {area}")Try running this code. When prompted, enter numerical values for the length and width. Observe how the program takes your text input, converts it to numbers suitable for calculation, performs the multiplication, and then prints a clear message with the computed area. What happens if you enter text instead of numbers? You should encounter a ValueError, highlighting the importance of type conversion and anticipating potential input issues (which we'll learn to handle more gracefully later).Example 2: Personalized GreetingThis example focuses on working with strings and user input to create a personalized message.Get User Name: Ask the user for their name.Get Favorite Item: Ask the user for something they like (e.g., a color, food, hobby).Combine and Display: Create and print a greeting that incorporates the user's inputs.# Get the user's name user_name = input("What is your name? ") # Get the user's favorite color favorite_color = input("What is your favorite color? ") # Create a personalized greeting using an f-string greeting = f"Hello, {user_name}! It's nice to meet you. {favorite_color} is a great color!" # Print the greeting print(greeting) # Example of a simple string method print(f"Your name in uppercase is: {user_name.upper()}")Run this script. Enter your name and favorite color when asked. Notice how the input() function captures your text directly into string variables. The f-string provides an easy way to embed these variables within a larger string to form the final greeting. We also included an example of using a string method, .upper(), to modify the case of the stored name.Example 3: Comparing NumbersLet's practice using comparison operators. This script will take two numbers and show the results of comparing them.Get Two Numbers: Prompt the user for two numbers, converting them to floats.Compare: Use comparison operators (>, <, ==, !=) to compare the numbers.Display Results: Print the boolean results (True or False) of each comparison.# Get the first number num1_str = input("Enter the first number: ") num1 = float(num1_str) # Get the second number num2_str = input("Enter the second number: ") num2 = float(num2_str) # Perform comparisons is_greater = num1 > num2 is_less = num1 < num2 is_equal = num1 == num2 is_not_equal = num1 != num2 # Display the results print(f"\nComparing {num1} and {num2}:") print(f"Is {num1} greater than {num2}? {is_greater}") print(f"Is {num1} less than {num2}? {is_less}") print(f"Is {num1} equal to {num2}? {is_equal}") print(f"Is {num1} not equal to {num2}? {is_not_equal}")Execute this code. Enter two different numbers, then try entering the same number twice. Observe the output. Comparison operators evaluate the relationship between values and produce a boolean result (True or False), which is fundamental for controlling program logic in later chapters.These examples cover the core concepts of this chapter: obtaining user input, storing it in variables, performing basic arithmetic and string operations, understanding data types and their conversion, and using comparison operators. Experiment with these scripts. Try different inputs, modify the calculations, or change the output messages. The more you practice, the more comfortable you'll become with these essential Python basics.