Conditional Programs
if / elif / else. Grades, vowels, triangle types. The bugs usually hide in the equal-to case.
20 programs · open one, then the next
The matching chapter is Day 8: Conditional Statements in the Python course. For a short check, try the Python quiz (300 questions). Every topic is listed on Python exercises.
Start with Grade Calculator- 01Grade CalculatorBeginner90 A, 80 B, ... else F. Check 0–100 first or a 107 becomes an A.Open example →py# Program to calculate grade from percentage percentage = float(input("Enter your percentage: "))
- 02Vowel or ConsonantBeginnerch in 'aeiou'. lower() first or 'A' looks like a consonant.Open example →py# Program to check whether a character is a vowel or consonant ch = input("Enter a single alphabet character: ").lower()
- 03Character Classification (Digit / Alpha / Special)Beginnerisdigit, isalpha, else special. Space counts as special. That bothers people.Open example →py# Program to classify a character as digit, alphabet, or special character ch = input("Enter a single character: ")
- 04Check Eligibility to VoteBeginner18 or older. Negative age is garbage, not "not eligible".Open example →py# Program to check voting eligibility age = int(input("Enter your age: "))
- 05Check Divisible by 5 and 11BeginnerBoth remainders 0. 55 yes, 10 no. `and` not `or`.Open example →py# Program to check if a number is divisible by both 5 and 11 num = int(input("Enter an integer: "))
- 06Check Armstrong NumberBeginnerCheck whether a given integer is an Armstrong (narcissistic) number.Open example →py# Program to check Armstrong number (order 3) num = int(input("Enter an integer: "))
- 07Check Perfect SquareBeginnerCheck whether a number is a perfect square.Open example →py# Program to check if a number is a perfect square import math
- 08Triangle Type CheckBeginnerDetermine if three sides form a valid triangle and its type (equilateral, isosceles, scalene).Open example →py# Program to check triangle validity and type a = float(input("Enter first side: ")) b = float(input("Enter second side: "))
- 09Check Strong NumberBeginnerCheck whether a number is a strong number (sum of factorials of digits).Open example →py# Program to check strong number import math
- 10Check Perfect NumberBeginnerCheck whether a number is a perfect number (sum of proper divisors equals the number).Open example →py# Program to check perfect number num = int(input("Enter a positive integer: "))
- 11Check Automorphic NumberBeginnerCheck whether a number is automorphic (its square ends with the same digits).Open example →py# Program to check automorphic number num = int(input("Enter an integer: "))
- 12Check Harshad NumberBeginnerCheck whether a number is a Harshad (Niven) number (divisible by sum of its digits).Open example →py# Program to check Harshad (Niven) number num = int(input("Enter an integer: "))
- 13Check Abundant NumberBeginnerCheck whether a number is abundant (sum of proper divisors is greater than the number).Open example →py# Program to check abundant number num = int(input("Enter a positive integer: "))
- 14Check Friendly PairIntermediateCheck whether two numbers form a friendly pair (same abundancy index).Open example →py# Program to check friendly pair def abundancy_index(n: int) -> float: total = 0
- 15Compare Floating NumbersIntermediateCompare two floating-point numbers with a tolerance to avoid precision issues.Open example →py# Program to compare two floating-point numbers import math
- 16Menu-Driven CalculatorBeginnerPrint a menu, read 1-4, then two numbers. Anything else is Invalid choice.Open example →py# Menu-driven calculator print("1. Addition") print("2. Subtraction")
- 17Bill Discount SystemBeginnerApply different discount slabs based on total bill amount.Open example →py# Program for bill discount system amount = float(input("Enter total bill amount: "))
- 18Login AuthenticationBeginnerSimulate a simple login system by comparing username and password with stored values.Open example →py# Simple login authentication USERNAME = "admin" PASSWORD = "secret123"
- 19Validate Password StrengthIntermediateCheck if a password is strong based on length and character type rules.Open example →py# Program to validate password strength import re
- 20Validate Email FormatIntermediateValidate whether a string matches a basic email address pattern.Open example →py# Program to validate email format using regex import re