CONDITIONAL STATEMENTS CODING PROGRAMS
Q1. Check if a number is positive.
num = 10
if num > 0:
print("Positive number")
Q2. Check if a number is negative or positive.
num = -5
if num >= 0:
print("Positive or Zero")
else:
print("Negative number")
Q3. Find the largest of two numbers.
a, b = 15, 20
if a > b:
print("a is greater")
else:
print("b is greater")
Q4. Find the largest of three numbers.
a, b, c = 12, 25, 9
if a >= b and a >= c:
print("a is largest")
elif b >= a and b >= c:
print("b is largest")
else:
print("c is largest")
Q5. Check whether a number is even or odd.
num = 7
if num % 2 == 0:
print("Even number")
else:
print("Odd number")
Q6. Check if a year is a leap year.
year = 2024
if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
print("Leap Year")
else:
print("Not a Leap Year")
Q7. Check grade based on marks.
marks = 85
if marks >= 90:
print("Grade A")
elif marks >= 75:
print("Grade B")
elif marks >= 50:
print("Grade C")
else:
print("Fail")
Q8. Check if a character is a vowel or consonant.
ch = "a"
if ch in "aeiouAEIOU":
print("Vowel")
else:
print("Consonant")
Q9. Check if a number is divisible by 5 and 11.
num = 55
if num % 5 == 0 and num % 11 == 0:
print("Divisible by 5 and 11")
else:
print("Not divisible")
Q10. Check if a number is positive, negative, or zero.
num = 0
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")
Q11. Nested if: Check if a number is even and also greater than 10.
num = 14
if num % 2 == 0:
if num > 10:
print("Even and greater than 10")
else:
print("Even but not greater than 10")
else:
print("Odd number")
Q12. Check if a student passed (marks ≥ 40) and if they scored distinction (≥
75).
marks = 78
if marks >= 40:
print("Pass")
if marks >= 75:
print("Distinction")
else:
print("Fail")
Q13. Check if a string is empty or not.
s = ""
if s:
print("String is not empty")
else:
print("String is empty")
Q14. Check eligibility to vote (age ≥ 18).
age = 19
if age >= 18:
print("Eligible to vote")
else:
print("Not eligible to vote")
Q15. Check whether a number is within a range (10 to 50).
num = 25
if 10 <= num <= 50:
print("Number is within the range 10-50")
else:
print("Number is outside the range")