Python Programs Using Only 'if' Statement
1. Check if Number is Positive
num = 5
if num > 0:
print("The number is positive.")
2. Check if Number is Even or Odd
num = 8
if num % 2 == 0:
print("Even number")
else:
print("Odd number")
3. Check for Voting Eligibility
age = 18
if age >= 18:
print("Eligible to vote")
else:
print("Not eligible to vote")
4. Check if Character is Vowel
ch = 'a'
if ch.lower() in 'aeiou':
print("Vowel")
else:
print("Consonant")
5. Compare Two Numbers
a = 10
b = 20
if a > b:
print("a is greater")
else:
print("b is greater")
6. Find Largest of Three Numbers
a = 10
b = 25
c = 15
if a > b and a > c:
print("a is largest")
elif b > c:
print("b is largest")
else:
print("c is largest")
7. 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")