Python Assignment 3
Python Assignment 3
Session 03 - Operators
Questions:
Questions:
1. Understanding Operators:
a. What are operators in Python, and why are they important?
b. List and describe three types of operators with examples.
c. Explain the difference between arithmetic, relational, and logical operators.
2. Arithmetic Operators:
a. Write a Python program that takes two numbers as input and calculates:
i. Their sum (+)
ii. Their difference (-)
iii. Their product (*)
iv. Their quotient (/)
v. Their remainder (%)
b. Add comments explaining each operation.
3. Relational and Logical Operators:
a. What are relational operators? Provide three examples of their usage.
b. What are logical operators? Explain how and, or, and not work with
examples.
c. Write a Python program that asks the user to enter their age and checks if
they are eligible to vote (age >= 18). Use both relational and logical operators.
4. Type Casting in Python:
a. What is type casting, and why is it necessary?
b. Convert the following values into different data types and print the results:
i. Integer to float
ii. Float to integer
iii. String containing a number to an integer
c. Write a program that asks the user for their birth year, converts it into an
integer, and calculates their current age.
5. Advanced Calculator Project:
a. Create a Python program that functions as a calculator with the following
features:
i. Takes two numbers as input from the user.
ii. Provides a menu for the user to choose an operation: addition,
subtraction, multiplication, division, modulus, exponentiation (**), and
floor division (//).
iii. Uses conditional statements to perform the chosen operation.
iv. Ensures the program handles division by zero with an appropriate
error message.
v. Implements a loop to allow multiple calculations until the user chooses
to exit.