Python Assignment 2 - Operators
Assignment 2
Python Operators: Arithmetic, Assignment and Relational
Student Name: ____________________________ Date: __________________
Topic: Arithmetic, assignment and relational operators Total Questions: 15
Instructions
1. Write each solution as a separate Python program.
2. Use only variables, data types, print statements and operators covered in class.
3. Do not use if-else, loops, functions, lists or advanced concepts for this assignment.
4. Use meaningful variable names such as total_marks, price, age, balance.
5. Print the result in a clean and readable format.
Coding Questions
Arithmetic Operators
Q1. Simple Calculator
Task: Create a Python program that stores two numbers in variables and prints their sum, difference,
product and division result.
Requirements:
- Use +, -, * and /.
- Take numbers as 40 and 8.
- Print each answer with a proper label.
Expected Output Example:
a = 40
b = 8
Sum = 48
Difference = 32
Product = 320
Division = 5.0
Page 1
Python Assignment 2 - Operators
Q2. Marks Percentage Calculator
Task: A student scored marks in 3 subjects. Store the marks in variables, find total marks and
percentage.
Requirements:
- Use arithmetic operators only.
- Assume each subject is out of 100.
- Use marks: 78, 85 and 92.
Expected Output Example:
Total Marks = 255
Percentage = 85.0
Q3. Area and Perimeter of Rectangle
Task: Store length and breadth of a rectangle. Calculate and print area and perimeter.
Requirements:
- Use length = 12 and breadth = 7.
- Formula: area = length * breadth.
- Formula: perimeter = 2 * (length + breadth).
Expected Output Example:
Area = 84
Perimeter = 38
Q4. Minutes to Hours and Minutes
Task: Store total minutes in a variable. Convert it into hours and remaining minutes.
Requirements:
- Use floor division // and modulus %.
- Use total_minutes = 135.
- Print hours and minutes separately.
Expected Output Example:
Hours = 2
Minutes = 15
Page 2
Python Assignment 2 - Operators
Q5. Bill Split Calculator
Task: Store a food bill amount and number of friends. Calculate how much each friend should pay.
Requirements:
- Use bill = 1250 and friends = 5.
- Use division operator.
- Print amount per friend.
Expected Output Example:
Each friend pays = 250.0
Assignment Operators
Q6. Wallet Balance Update
Task: A wallet has Rs. 500. Add Rs. 200, spend Rs. 150, and then print the final balance.
Requirements:
- Use assignment operators like += and -=.
- Do not directly calculate final value in one line.
- Show updated balance at the end.
Expected Output Example:
Final Balance = 550
Q7. Score Increment Game
Task: A player starts with score 10. Increase the score by 5, double it, then decrease it by 4.
Requirements:
- Use +=, *= and -=.
- Print the final score.
- Do not use if-else or loops.
Expected Output Example:
Final Score = 26
Q8. Product Price with Discount
Task: A product price is Rs. 1000. Increase the price by Rs. 200, then reduce it by Rs. 150 discount.
Requirements:
- Use += and -=.
- Print the final price.
- Use variable name price.
Expected Output Example:
Final Price = 1050
Page 3
Python Assignment 2 - Operators
Q9. Multiplying Savings
Task: A person has savings of Rs. 3000. Triple the savings using an assignment operator and print the
result.
Requirements:
- Use *= operator.
- Do not write savings = savings * 3.
- Print the updated savings.
Expected Output Example:
Updated Savings = 9000
Q10. Remainder Update
Task: Store a number as 29. Use an assignment operator to replace it with the remainder after division
by 5.
Requirements:
- Use %= operator.
- Print the updated number.
- This question checks modulus assignment.
Expected Output Example:
Updated Number = 4
Relational Operators
Q11. Age Comparison
Task: Store ages of two people and check who is older using relational operators.
Requirements:
- Use age1 = 18 and age2 = 21.
- Print results of age1 > age2 and age1 < age2.
- Output should show True or False.
Expected Output Example:
age1 > age2 = False
age1 < age2 = True
Page 4
Python Assignment 2 - Operators
Q12. Marks Pass Check
Task: Store marks of a student and check whether marks are greater than or equal to 35.
Requirements:
- Use marks = 42.
- Use >= operator.
- Print the boolean result with a label.
Expected Output Example:
Passed = True
Q13. Equal Number Check
Task: Store two numbers and check whether both numbers are equal or not equal.
Requirements:
- Use x = 25 and y = 25.
- Use == and != operators.
- Print both results.
Expected Output Example:
x == y = True
x != y = False
Q14. Price Comparison
Task: Store prices of two products and compare which one is cheaper.
Requirements:
- Use price_a = 499 and price_b = 599.
- Print price_a < price_b.
- Also print price_a > price_b.
Expected Output Example:
price_a < price_b = True
price_a > price_b = False
Q15. Height Eligibility Check
Task: A ride allows entry only if height is at least 120 cm. Store height and check eligibility.
Requirements:
- Use height = 118.
- Use >= operator.
- Print the boolean result.
Expected Output Example:
Eligible = False
Page 5
Python Assignment 2 - Operators
Submission Checklist
[ ] All 15 programs are completed.
[ ] Variable names are meaningful.
[ ] Output labels are clear.
[ ] Programs run without syntax errors.
Page 6