0% found this document useful (0 votes)
6 views2 pages

If Statement Programs Python

The document presents several Python programs that utilize only 'if' statements to perform various checks. These include determining if a number is positive, even or odd, checking voting eligibility, identifying vowels, comparing two numbers, finding the largest of three numbers, and grading based on marks. Each program is accompanied by sample code demonstrating its functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

If Statement Programs Python

The document presents several Python programs that utilize only 'if' statements to perform various checks. These include determining if a number is positive, even or odd, checking voting eligibility, identifying vowels, comparing two numbers, finding the largest of three numbers, and grading based on marks. Each program is accompanied by sample code demonstrating its functionality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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")

You might also like