1. Home
  2. Docs
  3. Programming with Python
  4. Control Statements
  5. 15+ if Statements Programs

15+ if Statements Programs

1.) Write a python program to Check if a number is positive.

num = 5
if num > 0:
    print("The number is positive.")

2.) Write a python program to take a number as input and Check if a number is positive.

num = int(input("Enter a number: "))
if num > 0:
    print("The number is positive.")

3.) Write a python program to Check if a person is eligible to vote.

age = int(input("Enter your age: "))
if age > = 18:
    print("You are eligible to vote.")

4.) Write a python program to Check if a number is even.

num = int(input("Enter a number: "))
if num % 2 = = 0:
    print("The number is even.")

5.) Write a python program to Check if a number is divisible by 5.

num = int(input("Enter a number: "))
if num % 5 = = 0:
    print("The number is divisible by 5.")

6.) Write a python program to Check if a number is positive or negative.

num = int(input("Enter a number: "))
if num > 0:
    print("The number is positive.")
else:
    print("The number is negative.")

7.) Write a python program to Check if a person is a minor or an adult.

age = int(input("Enter your age: "))
if age > = 18:
    print("You are an adult.")
else:
    print("You are a minor.")

8.) Write a python program to Check if a number is odd or even.

num = int(input("Enter a number: "))
if num % 2 = = 0:
    print("The number is even.")
else:
    print("The number is odd.")

9.) Write a python program to Check if a character is a vowel or consonant.

char = input("Enter a character: ").lower()
if char in 'aeiou':
    print("The character is a vowel.")
else:
    print("The character is a consonant.")

10.) Write a python program to Compare two numbers

num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
if num1 > num2:
    print("The first number is greater.")
else:
    print("The second number is greater or equal.")

11.) Write a python program to Check the grade of a student.

marks = int(input("Enter marks: "))
if marks > = 90:
    print("Grade: A")
elif marks > = 75:
    print("Grade: B")
elif marks > = 50:
    print("Grade: C")
else:
    print("Grade: F")

12.) Write a python program to Check the type of a number.

num = int(input("Enter a number: "))
if num > 0:
    print("The number is positive.")
elif num < 0:
    print("The number is negative.")
else:
    print("The number is zero.")

13.) Write a python program to Check the age group of a person.

age = int(input("Enter your age: "))
if age < 13:
    print("You are a child.")
elif age < 20:
    print("You are a teenager.")
elif age < 60:
    print("You are an adult.")
else:
    print("You are a senior citizen.")

14.) Write a python program to Check the day of the week.

day = int(input("Enter a day number (1-7): "))
if day = = 1:
    print("Monday")
elif day = = 2:
    print("Tuesday")
elif day = = 3:
    print("Wednesday")
elif day = = 4:
    print("Thursday")
elif day = = 5:
    print("Friday")
elif day = = 6:
    print("Saturday")
elif day = = 7:
    print("Sunday")
else:
    print("Invalid day number.")

15.) Write a python program to Check the traffic light signal.

signal = input("Enter traffic light color (red/yellow/green): ").lower()
if signal = = "red":
    print("Stop")
elif signal = = "yellow":
    print("Ready to stop")
elif signal = = "green":
    print("Go")
else:
    print("Invalid signal color.")

16.) Write a python program to Match day of the week.

day = int(input("Enter a day number (1-7): "))
match day:
    case 1:
        print("Monday")
    case 2:
        print("Tuesday")
    case 3:
        print("Wednesday")
    case 4:
        print("Thursday")
    case 5:
        print("Friday")
    case 6:
        print("Saturday")
    case 7:
        print("Sunday")
    case _:
        print("Invalid day number.")

17.) Write a python program to Match basic arithmetic operations.

operation = input("Enter operation (+, -, *, /): ")
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
match operation:
    case '+':
        print("Result:", num1 + num2)
    case '-':
        print("Result:", num1 - num2)
    case '*':
        print("Result:", num1 * num2)
    case '/':
        print("Result:", num1 / num2 if num2 != 0 else "Error: Division by zero")
    case _:
        print("Invalid operation.")

18.) Write a python program to Match vehicle type.

vehicle = input("Enter vehicle type (car, bike, bus): ").lower()
match vehicle:
    case "car":
        print("You chose a car.")
    case "bike":
        print("You chose a bike.")
    case "bus":
        print("You chose a bus.")
    case _:
        print("Invalid vehicle type.")

19.) Write a python program to Match month by number.

month = int(input("Enter a month number (1-12): "))
match month:
    case 1:
        print("January")
    case 2:
        print("February")
    case 3:
        print("March")
    case 4:
        print("April")
    case 5:
        print("May")
    case 6:
        print("June")
    case 7:
        print("July")
    case 8:
        print("August")
    case 9:
        print("September")
    case 10:
        print("October")
    case 11:
        print("November")
    case 12:
        print("December")
    case _:
        print("Invalid month number.")

20.) Write a python program to Match a season based on the month.

month = int(input("Enter a month number (1-12): "))
match month:
    case 12 | 1 | 2:
        print("Winter")
    case 3 | 4 | 5:
        print("Spring")
    case 6 | 7 | 8:
        print("Summer")
    case 9 | 10 | 11:
        print("Autumn")
    case _:
        print("Invalid month number.")

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *