Conditional Statements Practice
if, elif, else — decision-making in Python programs.
1
Positive or Negative
Easy
Given an integer N, determine whether it is positive, negative, or zero.
Input Format
A single integer N.
Output Format
Print "Positive" if N > 0, "Negative" if N < 0, or "Zero" if N is 0.
Sample Test Cases
|
Sample Input 1
-5 |
Sample Output 1
Negative |
|
Sample Input 2
0 |
Sample Output 2
Zero |
|
Sample Input 3
42 |
Sample Output 3
Positive |
Constraints
-10^9 ≤ N ≤ 10^9
Explanation
Use if-elif-else to compare N with 0.
2
Largest of Three Numbers
Easy
Given three integers, find and print the largest among them.
Input Format
Three space-separated integers A, B, C.
Output Format
Print the largest number.
Sample Test Cases
|
Sample Input 1
12 45 23 |
Sample Output 1
45 |
|
Sample Input 2
5 9 7 |
Sample Output 2
9 |
|
Sample Input 3
-3 -9 -1 |
Sample Output 3
-1 |
Constraints
-10^6 ≤ A, B, C ≤ 10^6
Explanation
Use nested if or comparisons to find the maximum.
3
Vowel or Consonant
Easy
Given a single character, check whether it is a vowel (a, e, i, o, u) or a consonant. Assume input is a lowercase letter.
Input Format
A single lowercase character.
Output Format
Print "Vowel" if the character is a vowel, otherwise print "Consonant".
Sample Test Cases
|
Sample Input 1
e |
Sample Output 1
Vowel |
|
Sample Input 2
b |
Sample Output 2
Consonant |
|
Sample Input 3
z |
Sample Output 3
Consonant |
Constraints
Character is a lowercase English letter.
Explanation
Use if and in operator: if ch in "aeiou".
4
Divisible by 3 and 5
Easy
Is N divisible by both 3 and 5?
Input Format
Single int N
Output Format
"Yes" or "No"
Sample Test Cases
|
Sample Input 1
15 |
Sample Output 1
Yes |
|
Sample Input 2
30 |
Sample Output 2
Yes |
|
Sample Input 3
10 |
Sample Output 3
No |
Constraints
1≤N≤10⁶
Explanation
N%3==0 and N%5==0
5
Alphabet Check
Easy
Is character an alphabet letter?
Input Format
Single char
Output Format
"Alphabet" or "Not an Alphabet"
Sample Test Cases
|
Sample Input 1
M |
Sample Output 1
Alphabet |
|
Sample Input 2
5 |
Sample Output 2
Not an Alphabet |
|
Sample Input 3
@ |
Sample Output 3
Not an Alphabet |
Constraints
Printable ASCII
Explanation
Check A-Z and a-z ranges.
6
Compare Two Numbers
Easy
Print relationship: A>B, A
Input Format
Two ints A B
Output Format
Relationship string.
Sample Test Cases
|
Sample Input 1
7 7 |
Sample Output 1
A == B |
|
Sample Input 2
5 8 |
Sample Output 2
A < B |
|
Sample Input 3
8 5 |
Sample Output 3
A > B |
Constraints
-10⁶≤A,B≤10⁶
Explanation
if-elif-else
7
Day of Week
Easy
Number 1-7 to day name (1=Sunday).
Input Format
Single int N (1-7)
Output Format
Day name.
Sample Test Cases
|
Sample Input 1
3 |
Sample Output 1
Tuesday |
|
Sample Input 2
1 |
Sample Output 2
Sunday |
|
Sample Input 3
7 |
Sample Output 3
Saturday |
Constraints
1≤N≤7
Explanation
List or if-elif.
8
Month Days
Easy
Number of days in month M (Feb=28, ignore leap).
Input Format
Single int M (1-12)
Output Format
Number of days.
Sample Test Cases
|
Sample Input 1
2 |
Sample Output 1
28 |
|
Sample Input 2
1 |
Sample Output 2
31 |
|
Sample Input 3
12 |
Sample Output 3
31 |
Constraints
1≤M≤12
Explanation
if-elif for 31/30/28 months.
9
Uppercase or Lowercase
Easy
Is letter uppercase or lowercase?
Input Format
Single letter
Output Format
"Uppercase" or "Lowercase"
Sample Test Cases
|
Sample Input 1
a |
Sample Output 1
Lowercase |
|
Sample Input 2
Z |
Sample Output 2
Uppercase |
|
Sample Input 3
m |
Sample Output 3
Lowercase |
Constraints
A-Z or a-z
Explanation
Check range.
10
Profit or Loss
Easy
CP vs SP: profit or loss?
Input Format
Two ints CP SP
Output Format
"Profit"/"Loss"/"No Profit No Loss"
Sample Test Cases
|
Sample Input 1
100 130 |
Sample Output 1
Profit |
|
Sample Input 2
50 50 |
Sample Output 2
No Profit No Loss |
|
Sample Input 3
130 100 |
Sample Output 3
Loss |
Constraints
1≤CP,SP≤10⁶
Explanation
Compare SP and CP.
1
Grade Calculator
Medium
Given marks in five subjects (out of 100 each), calculate the percentage and assign a grade: A (≥90%), B (≥75%), C (≥50%), D (≥35%), F (
Input Format
Five space-separated integers representing marks in five subjects.
Output Format
Print the percentage (rounded to 2 decimal places) on the first line and the grade on the second line.
Sample Test Cases
|
Sample Input 1
85 92 78 66 91 |
Sample Output 1
82.40 B |
|
Sample Input 2
40 45 50 55 60 |
Sample Output 2
50.00 C |
|
Sample Input 3
95 92 88 90 91 |
Sample Output 3
91.20 A |
Constraints
0 ≤ marks ≤ 100 for each subject.
Explanation
Calculate total / 5, then use if-elif ladder for grade assignment.
2
Triangle Type
Medium
Given three side lengths, determine the type of triangle: Equilateral (all sides equal), Isosceles (two sides equal), or Scalene (all sides different). Also check if the sides can form a valid triangle (sum of any two sides > third side).
Input Format
Three space-separated integers A, B, C representing side lengths.
Output Format
If the sides form a valid triangle, print "Equilateral", "Isosceles", or "Scalene". Otherwise print "Not a Triangle".
Sample Test Cases
|
Sample Input 1
5 5 8 |
Sample Output 1
Isosceles |
|
Sample Input 2
6 6 6 |
Sample Output 2
Equilateral |
|
Sample Input 3
2 3 7 |
Sample Output 3
Not a Triangle |
Constraints
1 ≤ A, B, C ≤ 10^4
Explanation
First validate: A + B > C, B + C > A, A + C > B. Then check equality conditions.
3
Leap Year Month Days
Medium
Days in month M of year Y, accounting for leap year.
Input Format
Two ints Y M
Output Format
Number of days.
Sample Test Cases
|
Sample Input 1
2024 2 |
Sample Output 1
29 |
|
Sample Input 2
1900 2 |
Sample Output 2
28 |
|
Sample Input 3
2000 2 |
Sample Output 3
29 |
Constraints
1000≤Y≤3000, 1≤M≤12
Explanation
Check leap year first.
4
Sort Three Numbers
Medium
Sort 3 ints ascending using conditionals only (no built-in sort).
Input Format
Three ints A B C
Output Format
Ascending order.
Sample Test Cases
|
Sample Input 1
9 5 7 |
Sample Output 1
5 7 9 |
|
Sample Input 2
-5 0 3 |
Sample Output 2
-5 0 3 |
|
Sample Input 3
1 1 1 |
Sample Output 3
1 1 1 |
Constraints
-10⁶≤A,B,C≤10⁶
Explanation
Compare and swap.
5
Electricity Bill
Medium
Slab: 100@₹5, 200@₹7, beyond@₹10
Input Format
Single int U (units)
Output Format
Total bill as int.
Sample Test Cases
|
Sample Input 1
350 |
Sample Output 1
2400 |
|
Sample Input 2
0 |
Sample Output 2
0 |
|
Sample Input 3
300 |
Sample Output 3
1900 |
Constraints
0≤U≤10000
Explanation
if-elif slabs.
6
Valid Triangle Angles
Medium
Sum=180 and all>0?
Input Format
Three ints A B C (degrees)
Output Format
"Valid" or "Invalid Triangle"
Sample Test Cases
|
Sample Input 1
60 60 60 |
Sample Output 1
Valid Triangle |
|
Sample Input 2
0 90 90 |
Sample Output 2
Invalid Triangle |
|
Sample Input 3
-10 100 90 |
Sample Output 3
Invalid Triangle |
Constraints
-10⁴≤A,B,C≤10⁴
Explanation
Check sum==180 and all>0.
7
Divisible by 2&3 but not 5
Medium
Is N divisible by 2 and 3 but not 5?
Input Format
Single int N
Output Format
"Yes" or "No"
Sample Test Cases
|
Sample Input 1
12 |
Sample Output 1
Yes |
|
Sample Input 2
30 |
Sample Output 2
No |
|
Sample Input 3
10 |
Sample Output 3
No |
Constraints
1≤N≤10⁶
Explanation
Logical AND/OR/NOT.
8
Character Type
Medium
Classify: Digit/Uppercase/Lowercase/Special
Input Format
Single char
Output Format
Category name.
Sample Test Cases
|
Sample Input 1
# |
Sample Output 1
Special Character |
|
Sample Input 2
7 |
Sample Output 2
Digit |
|
Sample Input 3
A |
Sample Output 3
Uppercase |
Constraints
Printable ASCII
Explanation
isdigit/isupper/islower.
9
Discount Calculator
Medium
Input Format
Single int P (price)
Output Format
Final price (2 dp).
Sample Test Cases
|
Sample Input 1
7500 |
Sample Output 1
6750.00 |
|
Sample Input 2
999 |
Sample Output 2
999.00 |
|
Sample Input 3
10000 |
Sample Output 3
8500.00 |
Constraints
1≤P≤10⁷
Explanation
if-elif discount percentage.
10
Find Middle Number
Medium
Middle of 3 distinct integers (not min or max).
Input Format
Three distinct ints A B C
Output Format
Middle number.
Sample Test Cases
|
Sample Input 1
12 5 8 |
Sample Output 1
8 |
|
Sample Input 2
1 2 3 |
Sample Output 2
2 |
|
Sample Input 3
-5 0 5 |
Sample Output 3
0 |
Constraints
-10⁶≤A,B,C≤10⁶, distinct
Explanation
(A+B+C)-min-max
1
Quadratic Equation Roots
Hard
Given coefficients a, b, c of a quadratic equation ax² + bx + c = 0, determine the nature of roots and print them. If discriminant D > 0: "Real and Distinct" with roots. If D = 0: "Real and Equal" with the root. If D < 0: "Imaginary".
Input Format
Three space-separated integers a, b, c.
Output Format
First line: nature of roots. Second line: the root(s) separated by space (rounded to 2 decimal places). If imaginary, print only "Imaginary".
Sample Test Cases
|
Sample Input 1
1 -5 6 |
Sample Output 1
Real and Distinct 3.00 2.00 |
|
Sample Input 2
1 -2 1 |
Sample Output 2
Real and Equal 1.00 |
|
Sample Input 3
1 2 5 |
Sample Output 3
Imaginary |
Constraints
-100 ≤ a, b, c ≤ 100, a ≠ 0
Explanation
D = b² - 4ac. Roots = (-b ± √D) / 2a. Use math.sqrt() for square root.
2
Date Validator
Hard
Validate DD MM YYYY (leap-aware).
Input Format
Three ints DD MM YYYY
Output Format
"Valid Date" or "Invalid Date"
Sample Test Cases
|
Sample Input 1
29 2 2024 |
Sample Output 1
Valid Date |
|
Sample Input 2
31 4 2023 |
Sample Output 2
Invalid Date |
|
Sample Input 3
29 2 1900 |
Sample Output 3
Invalid Date |
Constraints
1≤DD≤31, 1≤MM≤12, 1000-3000
Explanation
Check month, day ranges.
3
Calculator with Menu
Hard
Menu: 1.Add 2.Sub 3.Mul 4.Div 5.Mod
Input Format
Line1: A. Line2: B. Line3: choice
Output Format
Result. Div: 2 dp.
Sample Test Cases
|
Sample Input 1
15 4 3 |
Sample Output 1
60 |
|
Sample Input 2
10 5 2 |
Sample Output 2
5 |
|
Sample Input 3
10 3 5 |
Sample Output 3
1 |
Constraints
1≤A,B≤10⁶, B≠0 for div
Explanation
if-elif 5 options.
4
Zodiac Sign
Hard
Find zodiac from day and month.
Input Format
Two ints: day month
Output Format
Zodiac name.
Sample Test Cases
|
Sample Input 1
21 3 |
Sample Output 1
Aries |
|
Sample Input 2
19 1 |
Sample Output 2
Capricorn |
|
Sample Input 3
25 12 |
Sample Output 3
Capricorn |
Constraints
Valid dates
Explanation
Nested if-elif ranges.
5
Ticket Pricing
Hard
Base ₹200. Child≤12: 50% off. Senior≥60: 30% off. Weekend: +20%. IMAX: +₹50.
Input Format
Four inputs: age, weekend(y/n), imax(y/n), count
Output Format
Total cost int.
Sample Test Cases
|
Sample Input 1
10 yes yes 2 |
Sample Output 1
340 |
|
Sample Input 2
30 no no 1 |
Sample Output 2
200 |
|
Sample Input 3
65 no yes 1 |
Sample Output 3
190 |
Constraints
1≤age≤120, count 1-10
Explanation
Apply discounts and surcharges.
6
Roman to Integer
Hard
Convert Roman numeral string to int (IV=4, IX=9, etc.)
Input Format
Roman numeral string
Output Format
Integer value.
Sample Test Cases
|
Sample Input 1
MCMXCV |
Sample Output 1
1995 |
|
Sample Input 2
IV |
Sample Output 2
4 |
|
Sample Input 3
XLVIII |
Sample Output 3
48 |
Constraints
Len≤15
Explanation
Traverse: if cur
7
Number to Words
Hard
Convert N (1-999) to English words.
Input Format
Single int N
Output Format
English words.
Sample Test Cases
|
Sample Input 1
342 |
Sample Output 1
three hundred forty-two |
|
Sample Input 2
100 |
Sample Output 2
one hundred |
|
Sample Input 3
999 |
Sample Output 3
nine hundred ninety-nine |
Constraints
1≤N≤999
Explanation
Maps for 1-19, tens 20-90.
8
Age Category
Hard
Infant(0-2), Toddler(3-4), Child(5-12), Teen(13-19), Adult(20-39), Mid(40-59), Senior(60+)
Input Format
Single int age
Output Format
Category name.
Sample Test Cases
|
Sample Input 1
25 |
Sample Output 1
Adult |
|
Sample Input 2
1 |
Sample Output 2
Infant |
|
Sample Input 3
70 |
Sample Output 3
Senior |
Constraints
0≤age≤150
Explanation
if-elif ladder.
9
Triangle by Angles
Hard
Acute/all90. Validate first.
Input Format
Three ints A B C (degrees)
Output Format
"Acute"/"Right"/"Obtuse"/"Invalid"
Sample Test Cases
|
Sample Input 1
90 45 45 |
Sample Output 1
Right |
|
Sample Input 2
100 40 40 |
Sample Output 2
Obtuse |
|
Sample Input 3
150 20 10 |
Sample Output 3
Obtuse |
Constraints
1≤A,B,C≤360
Explanation
Validate sum=180 and all>0.
10
Days Between Two Dates
Hard
Calculate the number of days between two dates accounting for leap years.
Input Format
Two lines each with DD MM YYYY
Output Format
Print the number of days between them. Assume first date
Sample Test Cases
|
Sample Input 1
1 1 2024 1 1 2025 |
Sample Output 1
366 |
|
Sample Input 2
1 1 2023 31 12 2023 |
Sample Output 2
364 |
|
Sample Input 3
1 1 2000 1 1 2100 |
Sample Output 3
36525 |
Constraints
1-31, 1-12, 1000-3000
Explanation
Convert to days from a reference date using month day arrays and leap year logic.