Python Operators Practice Questions with Solutions

Python Operators Practice Questions are used to perform mathematical calculations, compare values, and combine conditions in Python. This practice set covers arithmetic, assignment, comparison, logical, and membership operators through beginner-friendly questions with complete solutions.


1. Python Program to Perform Basic Arithmetic Operations

Difficulty: Foundation

Problem Statement

Write a Python program to perform addition, subtraction, multiplication, division, floor division, modulus, and exponentiation on two numbers.

Expected Output

Number 1: 20
Number 2: 6

Addition: 26
Subtraction: 14
Multiplication: 120
Division: 3.3333333333333335
Floor Division: 3
Modulus: 2
Exponentiation: 64000000

Python Solution

num1 = 20
num2 = 6

print("Addition:", num1 + num2)
print("Subtraction:", num1 - num2)
print("Multiplication:", num1 * num2)
print("Division:", num1 / num2)
print("Floor Division:", num1 // num2)
print("Modulus:", num1 % num2)
print("Exponentiation:", num1 ** num2)

Explanation

Python provides different arithmetic operators for performing mathematical calculations.

Concepts Covered

  • Arithmetic Operators
  • +, -, *, /, //, %, **

2. Python Program to Find the Quotient and Remainder

Difficulty: Foundation

Problem Statement

Write a Python program to find the quotient and remainder when one number is divided by another.

Expected Output

Quotient: 3
Remainder: 2

Python Solution

num1 = 20
num2 = 6

print("Quotient:", num1 // num2)
print("Remainder:", num1 % num2)

Explanation

// returns the quotient, while % returns the remainder.

Concepts Covered

  • Floor Division
  • Modulus Operator

3. Python Program to Use Assignment Operators

Difficulty: Foundation

Problem Statement

Write a Python program to demonstrate the use of assignment operators.

Python Solution

num = 10

num += 5
print(num)

num -= 3
print(num)

num *= 2
print(num)

num //= 4
print(num)

Expected Output

15
12
24
6

Explanation

Assignment operators update the value of a variable without writing the variable name repeatedly.

Concepts Covered

  • +=
  • -=
  • *=
  • //=

4. Python Program to Compare Two Numbers

Difficulty: Foundation

Problem Statement

Write a Python program to compare two numbers using comparison operators.

Python Solution

a = 15
b = 20

print(a == b)
print(a != b)
print(a > b)
print(a < b)
print(a >= b)
print(a <= b)

Expected Output

False
True
False
True
False
True

Explanation

Comparison operators return either True or False.

Concepts Covered

  • ==
  • !=
  • <
  • =
  • <=

5. Python Program to Check Voting Eligibility

Difficulty: Practice

Problem Statement

A person is eligible to vote if their age is 18 or above. Write a Python program using the comparison operator.

Python Solution

age = 21

print(age >= 18)

Expected Output

True

Explanation

The >= operator checks whether the age is greater than or equal to 18.

Concepts Covered

  • Comparison Operators

6. Python Program to Use Logical Operators

Difficulty: Practice

Problem Statement

Write a Python program to demonstrate the use of and, or, and not.

Python Solution

age = 22
has_id = True

print(age >= 18 and has_id)
print(age < 18 or has_id)
print(not has_id)

Expected Output

True
True
False

Explanation

Logical operators combine multiple conditions.

Concepts Covered

  • and
  • or
  • not

7. Python Program to Check Membership Using in Operator

Difficulty: Practice

Problem Statement

Write a Python program to check whether "Python" exists in a list.

Python Solution

courses = ["Python", "Java", "C++"]

print("Python" in courses)

Expected Output

True

Explanation

The in operator checks whether a value exists in a sequence.

Concepts Covered

  • Membership Operator
  • in

8. Python Program to Check Membership Using not in Operator

Difficulty: Practice

Problem Statement

Write a Python program to check whether "PHP" is not available in the list.

Python Solution

courses = ["Python", "Java", "C++"]

print("PHP" not in courses)

Expected Output

True

Explanation

The not in operator returns True when the value is not present in the sequence.

Concepts Covered

  • Membership Operator
  • not in

9. Python Program to Calculate the Total Bill

Difficulty: Challenge

Problem Statement

A customer purchased items worth ₹1500. A discount of ₹200 is applied. Write a Python program to calculate the final bill amount.

Python Solution

total_amount = 1500
discount = 200

final_amount = total_amount - discount

print("Final Bill:", final_amount)

Expected Output

Final Bill: 1300

Explanation

The subtraction operator is used to reduce the discount from the total amount.

Concepts Covered

  • Arithmetic Operators
  • Variables

10. Python Program to Calculate Simple Interest

Difficulty: Challenge

Problem Statement

Write a Python program to calculate simple interest using the formula:

Simple Interest = (Principal × Rate × Time) / 100

Use the following values:

  • Principal = 10000
  • Rate = 8
  • Time = 2 years

Python Solution

principal = 10000
rate = 8
time = 2

simple_interest = (principal * rate * time) / 100

print("Simple Interest:", simple_interest)

Expected Output

Simple Interest: 1600.0

Explanation

Arithmetic operators are used to calculate the simple interest based on the given formula.

Concepts Covered

  • Arithmetic Operators
  • Mathematical Expressions

Chapter Summary

After completing this chapter, you have learned:

  • Arithmetic Operators (+, -, *, /, //, %, **)
  • Assignment Operators (=, +=, -=, *=, //=)
  • Comparison Operators (==, !=, >, <, >=, <=)
  • Logical Operators (and, or, not)
  • Membership Operators (in, not in)
  • Using operators in real-world Python programs

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top