Python Operators Examples
Problem 1: Sum of two numbers given by user
Example 1
num1 = int(input(“Enter 1st number: “))
num2 = int(input(“Enter 2nd number: “))
sum = num1 + num2
print("Sum =", sum) Problem 2: Swap two numbers without temporary variable
Example 2
a = int(input(“Enter a = “))
b = int(input(“Enter b = “))
a = a + b
b = a - b
a = a - b
print("After swap: a =", a, "b =", b) Problem 3: Total cost with 25% discount and 15% tax
Example 3
price = int(input(“Enter Product Price: “))
price -= (price * 25 / 100)
price += (price * 15 / 100
print("Final Price =", price) Problem 4: Reverse two-digit number
Example 4
num = int(input(“Enter a number: “))
tens = num // 10
units = num % 10
rev = units * 10
rev += tens
print("Reversed =", rev) Problem 5: Marks calculator
Example 5
total = int(input("Enter your total marks: "))
marks = int(input("Enter your marks: "))
per = (marks/total)*100
print(f"Your Score: {per: 0.2f}%")