Problems on conditional
🌱 1. Check Positive, Negative, or Zero
Problem:
Check if a number is positive, negative, or zero.
Example Input:
5
Example Output:
Positive
Explanation:
The condition checks whether the number 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
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
Explanation:
Check whether the given marks are above or below the passing mark.
🧮 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
Explanation:
Use conditional comparison operators (>
, <
) to identify the larger number.
🕰 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
Explanation:
If age is greater than or equal to 18, print eligible; otherwise, not eligible.
🧊 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
Explanation:
If the year is divisible by 4, it’s considered a leap year (simple rule version).
🔢 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
Explanation:
Use multiple conditions with and
to compare three values.
🕹 8. Check Character Type
Problem:
Check whether a given character is a vowel or consonant.
Example Input:
Input: e
Output: Vowel
Explanation:
Use in
operator to check if the letter belongs to the set of vowels.
💰 9. Calculate Discount
Problem:
If purchase amount > 1000, apply 10% discount.
Example Input:
amount = 1500
Example Output:
Discounted price: 1350.0
Explanation:
Apply the discount only when the amount crosses the threshold.
🧾 10. Grade Calculator
Problem:
Assign a grade based on marks.
Marks | Grade |
---|---|
90–100 | A |
75–89 | B |
50–74 | C |
Below 50 | Fail |
Example Input:
marks = 82
Example Output:
Grade B
Explanation:
Use chained if-elif-else
conditions to decide the grade range.
🔢 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
Explanation:
Classic conditional challenge to test multiple combined conditions.
✊✋✌️ 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!
Explanation:
Each choice beats one and loses to another — handle all possibilities using if
, elif
, and else
.