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
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
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
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
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
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
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
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
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
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
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
11. Python Program to Check Whether a Number is Positive, Negative, or Zero Using Comparison Operators
Problem Statement
Write a Python program to determine whether a number is positive, negative, or zero using comparison operators.
Python Solution
num = float(input("Enter a number: "))
if num > 0:
print("Positive Number")
elif num < 0:
print("Negative Number")
else:
print("Zero")
Sample Output
Enter a number: -15
Negative Number
Explanation
The program uses comparison operators (>, <) with if-elif-else statements to classify the number.
Concepts Covered
- Comparison Operators
- if-elif-else
- User Input
12. Python Program to Check Eligibility for Voting Using Logical Operators
Problem Statement
Write a Python program to check whether a person is eligible to vote. A person is eligible only if they are 18 years or older and have Indian citizenship.
Python Solution
age = int(input("Enter your age: "))
citizen = input("Are you an Indian citizen? (yes/no): ").lower()
if age >= 18 and citizen == "yes":
print("Eligible to Vote")
else:
print("Not Eligible")
Sample Output
Enter your age: 22
Are you an Indian citizen? (yes/no): yes
Eligible to Vote
Explanation
The logical AND (and) operator ensures both conditions are true before granting eligibility.
Concepts Covered
- Logical Operators
- and Operator
- Conditional Statements
13. Python Program to Calculate Electricity Bill Using Arithmetic and Conditional Operators
Problem Statement
Write a Python program to calculate the electricity bill based on units consumed.
- First 100 units → ₹5 per unit
- Next 100 units → ₹7 per unit
- Above 200 units → ₹10 per unit
Python Solution
units = int(input("Enter units consumed: "))
if units <= 100:
bill = units * 5
elif units <= 200:
bill = (100 * 5) + ((units - 100) * 7)
else:
bill = (100 * 5) + (100 * 7) + ((units - 200) * 10)
print("Electricity Bill: ₹", bill)
Sample Output
Enter units consumed: 250
Electricity Bill: ₹ 1700
Explanation
This program combines arithmetic operators with conditional statements to calculate the total bill.
Concepts Covered
- Arithmetic Operators
- Conditional Statements
- Real-world Problem Solving
14. Python Program to Find the Largest of Three Numbers Using Logical Operators
Problem Statement
Write a Python program to find the largest among three numbers entered by the user.
Python Solution
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b and a >= c:
print("Largest Number:", a)
elif b >= a and b >= c:
print("Largest Number:", b)
else:
print("Largest Number:", c)
Sample Output
Enter first number: 15
Enter second number: 42
Enter third number: 27
Largest Number: 42
Explanation
Logical operators are used to compare multiple conditions and determine the largest value.
Concepts Covered
- Comparison Operators
- Logical Operators
- if-elif-else
15. Python Program to Build a Simple Calculator Using Operators
Problem Statement
Write a Python program to perform addition, subtraction, multiplication, division, modulus, and exponentiation based on the user’s choice.
Python Solution
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Modulus")
print("6. Exponent")
choice = int(input("Enter your choice: "))
if choice == 1:
print("Result:", num1 + num2)
elif choice == 2:
print("Result:", num1 - num2)
elif choice == 3:
print("Result:", num1 * num2)
elif choice == 4:
print("Result:", num1 / num2)
elif choice == 5:
print("Result:", num1 % num2)
elif choice == 6:
print("Result:", num1 ** num2)
else:
print("Invalid Choice")
Sample Output
Enter first number: 12
Enter second number: 4
Enter your choice: 3
Result: 48.0
Explanation
This project combines arithmetic operators with conditional logic to create a simple calculator.
Concepts Covered
- Arithmetic Operators
- Conditional Statements
- User Input
- Calculator Program
Frequently Asked Questions (FAQs)
1. What are operators in Python?
Operators are special symbols used to perform operations on variables and values. They help perform calculations, comparisons, logical operations, and assignments.
2. What are the different types of operators in Python?
The main types of Python operators are:
- Arithmetic Operators
- Comparison (Relational) Operators
- Assignment Operators
- Logical Operators
- Bitwise Operators
- Membership Operators
- Identity Operators
3. What is the difference between = and == in Python?
=is the assignment operator used to assign values to variables.==is the comparison operator used to check whether two values are equal.
Example:
x = 10 # Assignment
print(x == 10) # Comparison
4. What is the difference between and, or, and not operators?
andreturnsTrueif both conditions are true.orreturnsTrueif at least one condition is true.notreverses the Boolean value.
5. What are arithmetic operators in Python?
Arithmetic operators perform mathematical calculations.
Examples include:
+Addition-Subtraction*Multiplication/Division%Modulus//Floor Division**Exponentiation
6. Why are comparison operators important?
Comparison operators compare two values and return either True or False. They are commonly used in if statements, loops, filtering, and decision-making programs.
7. Where are Python operators used in real-world applications?
Python operators are used in almost every Python application, including:
- Data Analysis
- Machine Learning
- Web Development
- Automation Scripts
- Financial Calculations
- Scientific Computing
- Game Development
- Business Applications
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.
