Solution of Conditional

October 7, 2025

🌱 1. Check Positive, Negative, or Zero

Problem:
Check if a number is positive, negative, or zero.

Example Input:

5

Example Output:

Positive

Solution:

num = 5

if num > 0:
    print("Positive")
elif num < 0:
    print("Negative")
else:
    print("Zero")

Explanation:
The condition checks whether num is greater than, less than, or equal to zero.


🧩 2. Check Even or Odd

Problem:
Determine whether a number is even or odd.

Example Input:

8

Example Output:

Even

Solution:

num = 8

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

Explanation:
% (modulus) gives the remainder.
If remainder is 0, it’s even; otherwise, odd.


🎓 3. Pass or Fail

Problem:
Print “Pass” if score ≥ 40, else “Fail”.

Example Input:

35

Example Output:

Fail

Solution:

score = 35

if score >= 40:
    print("Pass")
else:
    print("Fail")


🧮 4. Find the Greater Number

Problem:
Compare two numbers and print the greater one.

Example Input:

a = 15, b = 20

Example Output:

20 is greater

Solution:

a = 15
b = 20

if a > b:
    print(f"{a} is greater")
else:
    print(f"{b} is greater")


🕰 5. Check Voting Eligibility

Problem:
Check if a person is eligible to vote (age ≥ 18).

Example Input:

age = 17

Example Output:

Not eligible to vote

Solution:

age = 17

if age >= 18:
    print("Eligible to vote")
else:
    print("Not eligible to vote")


🧊 6. Check Leap Year (Simple)

Problem:
Check if a year is divisible by 4 (simple leap year rule).

Example Input:

2024

Example Output:

Leap year

Solution:

year = 2024

if year % 4 == 0:
    print("Leap year")
else:
    print("Not a leap year")


🔢 7. Find Largest of Three Numbers

Problem:
Find the largest among three numbers.

Example Input:

a = 10, b = 25, c = 15

Example Output:

25 is the largest

Solution:

a = 10
b = 25
c = 15

if a >= b and a >= c:
    print(f"{a} is the largest")
elif b >= a and b >= c:
    print(f"{b} is the largest")
else:
    print(f"{c} is the largest")


🕹 8. Check Character Type

Problem:
Check whether a given character is a vowel or consonant.

Example Input:

Input: e
Output: Vowel

Solution:

ch = "e"

if ch in "aeiouAEIOU":
    print("Vowel")
else:
    print("Consonant")


💰 9. Calculate Discount

Problem:
If purchase amount > 1000, apply 10% discount.

Example Input:

amount = 1500

Example Output:

Discounted price: 1350.0

Solution:

amount = 1500

if amount > 1000:
    discount = amount * 0.10
    amount -= discount

print("Discounted price:", amount)


🧾 10. Grade Calculator

Problem:
Assign a grade based on marks.

MarksGrade
90–100A
75–89B
50–74C
Below 50Fail

Example Input:

marks = 82

Example Output:

Grade B

Solution:

marks = 82

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


🔢 11. FizzBuzz (Without Loops)

Problem:
Given a number,

  • Print "Fizz" if divisible by 3
  • Print "Buzz" if divisible by 5
  • Print "FizzBuzz" if divisible by both
  • Otherwise, print the number itself

Example Input:

15

Example Output:

FizzBuzz

Solution:

num = 15

if num % 3 == 0 and num % 5 == 0:
    print("FizzBuzz")
elif num % 3 == 0:
    print("Fizz")
elif num % 5 == 0:
    print("Buzz")
else:
    print(num)

Explanation:
This is the classic “FizzBuzz” logic — simple yet powerful practice for condition checking.


✊✋✌️ 12. Rock, Paper, Scissors (Simple Version)

Problem:
Take two players’ choices (rock, paper, or scissors) and print who wins.

Example Input:

player1 = "rock"
player2 = "scissors"

Example Output:

Player 1 wins!

Solution:

player1 = "rock"
player2 = "scissors"

if player1 == player2:
    print("It's a tie!")
elif (player1 == "rock" and player2 == "scissors") or \
     (player1 == "scissors" and player2 == "paper") or \
     (player1 == "paper" and player2 == "rock"):
    print("Player 1 wins!")
else:
    print("Player 2 wins!")

Explanation:
Each choice beats one and loses to another — conditions handle all combinations.

© Copyright 2025 Fessorpro

Terms of Service / Privacy Policy