0% found this document useful (0 votes)
16 views3 pages

? 1. Operators

all u need to know abt python coding

Uploaded by

sk.prithul17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

? 1. Operators

all u need to know abt python coding

Uploaded by

sk.prithul17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

🔢 1.

Operators
Q1: Perform arithmetic operations on two numbers
python
Copy
Edit
a = 10
b = 5
print("Addition:", a + b)
print("Subtraction:", a - b)
print("Multiplication:", a * b)
print("Division:", a / b)
print("Floor Division:", a // b)
print("Modulus:", a % b)
print("Power:", a ** b)
Q2: Use comparison and logical operators
python
Copy
Edit
x = 8
y = 12
print("Is x equal to y?", x == y)
print("Is x less than y?", x < y)
print("Logical AND:", x < 10 and y > 10)
print("Logical OR:", x < 10 or y < 10)
✅ 2. Boolean – True or False
Q3: Write expressions that return booleans
python
Copy
Edit
a = 4
b = 6
print(a > 2) # True
print(a < b) # True
print(a == b) # False
print(not(a == b)) # True
🔁 3. If..Else
Q4: Check if a number is even or odd
python
Copy
Edit
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
Q5: Check if a number is positive or negative
python
Copy
Edit
num = int(input("Enter a number: "))
if num >= 0:
print("Positive")
else:
print("Negative")
🪜 4. Elif
Q6: Grade system based on marks
python
Copy
Edit
marks = int(input("Enter marks: "))
if marks >= 90:
print("Grade A")
elif marks >= 70:
print("Grade B")
elif marks >= 50:
print("Grade C")
else:
print("Fail")
Q7: Categorize age group
python
Copy
Edit
age = int(input("Enter your age: "))
if age < 13:
print("Child")
elif age < 20:
print("Teen")
elif age < 60:
print("Adult")
else:
print("Senior Citizen")
🧩 5. Nested If..Else
Q8: Check if a number is positive, then check if it's divisible by 5
python
Copy
Edit
num = int(input("Enter a number: "))
if num > 0:
if num % 5 == 0:
print("Positive and divisible by 5")
else:
print("Positive but not divisible by 5")
else:
print("Not a positive number")
🔄 6. For Loop
Q9: Print numbers from 1 to 10
python
Copy
Edit
for i in range(1, 11):
print(i)
Q10: Print multiplication table of a number
python
Copy
Edit
num = int(input("Enter a number: "))
for i in range(1, 11):
print(f"{num} x {i} = {num * i}")
Q11: Find factorial of a number
python
Copy
Edit
num = int(input("Enter a number: "))
fact = 1
for i in range(1, num + 1):
fact *= i
print("Factorial is", fact)
Q12: Print square of numbers from 1 to 5
python
Copy
Edit
for i in range(1, 6):
print(f"{i} squared is {i**2}")

You might also like