Python Conditional Statements Practice Questions with Solutions

Conditional statements help a program make decisions based on different conditions. In this Python conditional statements practice Questions with Solutions set, you’ll learn how to use if, if...else, if...elif...else, and nested if statements through beginner-friendly Python programs.


1. Python Program to Check Whether a Number is Positive or Negative

Difficulty: Foundation

Problem Statement

Write a Python program to check whether a given number is positive or negative.

Python Solution

number = int(input("Enter a number: "))

if number >= 0:
    print("Positive Number")
else:
    print("Negative Number")

Sample Output

Enter a number: 25
Positive Number

Explanation

The program checks whether the entered number is greater than or equal to zero.

Concepts Covered

  • if…else statement

2. Python Program to Check Whether a Number is Even or Odd

Difficulty: Foundation

Problem Statement

Write a Python program to check whether a number is even or odd.

Python Solution

number = int(input("Enter a number: "))

if number % 2 == 0:
    print("Even Number")
else:
    print("Odd Number")

Sample Output

Enter a number: 18
Even Number

Explanation

If the remainder after dividing by 2 is zero, the number is even.

Concepts Covered

  • if…else
  • Modulus operator

3. Python Program to Check Voting Eligibility

Difficulty: Foundation

Problem Statement

Write a Python program to check whether a person is eligible to vote. The minimum voting age is 18 years.

Python Solution

age = int(input("Enter your age: "))

if age >= 18:
    print("Eligible for Voting")
else:
    print("Not Eligible for Voting")

Sample Output

Enter your age: 20
Eligible for Voting

Explanation

The program compares the user’s age with the minimum voting age.

Concepts Covered

  • Comparison operator
  • if…else

4. Python Program to Find the Largest of Two Numbers

Difficulty: Foundation

Problem Statement

Write a Python program to find the larger of two numbers entered by the user.

Python Solution

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

if num1 > num2:
    print("Largest Number:", num1)
else:
    print("Largest Number:", num2)

Sample Output

Enter first number: 35
Enter second number: 18
Largest Number: 35

Explanation

The program compares two numbers and displays the greater value.

Concepts Covered

  • Comparison operators
  • if…else

5. Python Program to Find the Largest of Three Numbers

Difficulty: Practice

Problem Statement

Write a Python program to find the largest among three numbers using if...elif...else.

Python Solution

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))

if num1 >= num2 and num1 >= num3:
    print("Largest Number:", num1)
elif num2 >= num1 and num2 >= num3:
    print("Largest Number:", num2)
else:
    print("Largest Number:", num3)

Sample Output

Enter first number: 45
Enter second number: 18
Enter third number: 30
Largest Number: 45

Explanation

The program compares all three numbers and prints the largest one.

Concepts Covered

  • if…elif…else
  • Logical operators

6. Python Program to Check Whether a Year is a Leap Year

Difficulty: Practice

Problem Statement

Write a Python program to check whether a given year is a leap year.

Python Solution

year = int(input("Enter a year: "))

if (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0):
    print("Leap Year")
else:
    print("Not a Leap Year")

Sample Output

Enter a year: 2024
Leap Year

Explanation

A leap year is divisible by 400 or divisible by 4 but not by 100.

Concepts Covered

  • Nested conditions
  • Logical operators

7. Python Program to Calculate Grade Based on Marks

Difficulty: Practice

Problem Statement

Write a Python program to display the grade based on the following criteria:

  • 90 and above → A
  • 75–89 → B
  • 60–74 → C
  • 40–59 → D
  • Below 40 → Fail

Python Solution

marks = int(input("Enter marks: "))

if marks >= 90:
    print("Grade A")
elif marks >= 75:
    print("Grade B")
elif marks >= 60:
    print("Grade C")
elif marks >= 40:
    print("Grade D")
else:
    print("Fail")

Sample Output

Enter marks: 82
Grade B

Explanation

if...elif...else helps check multiple conditions in sequence.

Concepts Covered

  • Multiple conditions
  • if…elif…else

8. Python Program to Check Whether a Character is a Vowel or Consonant

Difficulty: Practice

Problem Statement

Write a Python program to check whether a character entered by the user is a vowel or a consonant.

Python Solution

character = input("Enter a character: ").lower()

if character in "aeiou":
    print("Vowel")
else:
    print("Consonant")

Sample Output

Enter a character: a
Vowel

Explanation

The in operator checks whether the character exists in the string "aeiou".

Concepts Covered

  • if…else
  • Membership operator

9. Python Program to Check Username and Password

Difficulty: Challenge

Problem Statement

Write a Python program to check whether the entered username and password are correct.

  • Username: admin
  • Password: 12345

Python Solution

username = input("Enter username: ")
password = input("Enter password: ")

if username == "admin" and password == "12345":
    print("Login Successful")
else:
    print("Invalid Username or Password")

Sample Output

Enter username: admin
Enter password: 12345
Login Successful

Explanation

The program checks two conditions using the and operator.

Concepts Covered

  • Logical operators
  • Multiple conditions

10. Python Program to Check the Largest Among Four Numbers

Difficulty: Challenge

Problem Statement

Write a Python program to find the largest among four numbers entered by the user.

Python Solution

num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))
num4 = int(input("Enter fourth number: "))

largest = num1

if num2 > largest:
    largest = num2

if num3 > largest:
    largest = num3

if num4 > largest:
    largest = num4

print("Largest Number:", largest)

Sample Output

Enter first number: 12
Enter second number: 35
Enter third number: 28
Enter fourth number: 42
Largest Number: 42

Explanation

The program updates the value of largest whenever it finds a bigger number.

Concepts Covered

  • Multiple if statements
  • Comparison operators

Chapter Summary

After completing this chapter, you have learned:

  • if statement
  • if...else statement
  • if...elif...else statement
  • Nested conditions
  • Comparison operators
  • Logical operators
  • Decision-making in Python
  • Solving real-world problems using conditional statements

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top