Python Exercise - Operators and Data Structures

Introduction

This unit covers Python’s basic operators, focusing on arithmetic, comparison, and logical operators. You will practice using these operators through multiple tasks to solidify your understanding.

Task 1: Arithmetic and Comparison Operators

Description:

Practice using arithmetic and comparison operators in Python.

Instructions:

  1. Define two variables: a = 10 and b = 5.
  2. Perform the following arithmetic operations and print the results:
    • Modulus: Calculate the remainder when a is divided by b.
    • Exponentiation: Raise a to the power of b.
  3. Perform the following comparison operations and print whether each statement is true or false:
    • Check if a is equal to b.
    • Check if a is not equal to b.
    • Check if a is greater than b.
    • Check if a is less than or equal to b.

Task 2: Logical and Combined Operations

Description:

Use comparison operators in combination with logical operators (and, or, not) in Python.

Instructions:

  1. Define the same two variables: a = 10 and b = 5.
  2. Perform the following combined operations:
    • Check if a is greater than 8 and b is less than 10.
    • Check if a is equal to 10 or b is equal to 10.
    • Use the not operator to invert a comparison result.
  3. Print the result of each logical operation.

Updated: