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 CalculatorBeginnerCheck marks before assigning a letter grade in Python. A first conditional ladder shows why high cutoffs come first and why 107% must not receive an A.Open example →py# Program to calculate grade from percentage percentage = float(input("Enter your percentage: "))
- 02Vowel or ConsonantBeginnerNormalize A to a before testing Python vowel membership. A beginner character exercise combines validation with an honest look at its English-only vowel rule.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)BeginnerIs @ a letter, digit, or something else? Classify one Python character, validate its length, and learn the Unicode limits of this beginner branching exercise.Open example →py# Program to classify a character as digit, alphabet, or special character ch = input("Enter a single character: ")
- 04Check Eligibility to VoteBeginnerInclude age 18 and reject negative ages in a Python threshold exercise. New programmers separate invalid input from a failed eligibility rule at the boundary.Open example →py# Program to check voting eligibility age = int(input("Enter your age: "))
- 05Check Divisible by 5 and 11BeginnerBoth is not the same as either: test Python remainders for 5 and 11 together. Beginner examples use 55, zero, and a number that satisfies only one condition.Open example →py# Program to check if a number is divisible by both 5 and 11 num = int(input("Enter an integer: "))
- 06Check Armstrong NumberBeginnerProve that 153 equals its powered-digit sum with Python. A beginner walkthrough derives the exponent from digit count and safely handles negative responses.Open example →py# Program to check Armstrong number num = int(input("Enter an integer: "))
- 07Check Perfect SquareBeginnerUse an exact Python integer square root to test perfect squares. Beginners compare the squared candidate with the input without introducing float rounding.Open example →py# Program to check if a number is a perfect square import math
- 08Triangle Type CheckBeginnerValidate three Python side lengths before naming the triangle. First-year logic practice covers strict inequalities, equal sides, and the flat 1-2-3 case.Open example →py# Program to check triangle validity and type a = float(input("Enter first side: ")) b = float(input("Enter second side: "))
- 09Check Strong NumberBeginnerExplain 145 through 1! + 4! + 5! in a Python digit loop. New programmers practice extraction, a running sum, and why the single zero digit contributes one.Open example →py# Program to check strong number import math
- 10Check Perfect NumberBeginnerAdd the proper divisors of 6 and recover 6 with Python. A beginner number-property lesson excludes the input itself and tests the often-missed value one.Open example →py# Program to check perfect number num = int(input("Enter a positive integer: "))
- 11Check Automorphic NumberBeginnerDoes 25 appear at the end of its square? Answer with Python multiplication and endswith in a beginner exercise that separates numeric value from digit text.Open example →py# Program to check automorphic number num = int(input("Enter an integer: "))
- 12Check Harshad NumberBeginnerDivide 18 by its digit sum to check a Python Harshad number. Beginner steps explain generators, positive-input rules, and short-circuit protection from zero.Open example →py# Program to check Harshad (Niven) number num = int(input("Enter an integer: "))
- 13Check Abundant NumberBeginner12 has proper divisors totaling 16. Follow this Python beginner search to understand abundant numbers and why an equal divisor sum belongs to another category.Open example →py# Program to check abundant number num = int(input("Enter a positive integer: "))
- 14Check Friendly PairIntermediateCompare 6 and 28 through their divisor-sum ratios in Python. An introductory helper-function exercise explains friendly numbers and the limits of float equality.Open example →py# Program to check friendly pair def abundancy_index(n: int) -> float: total = 0
- 15Compare Floating NumbersIntermediateChoose what close means before comparing Python floats. A beginner math.isclose example uses an absolute tolerance and separates approximate equality from order.Open example →py# Program to compare two floating-point numbers import math
- 16Menu-Driven CalculatorBeginnerRoute a Python menu choice to addition, subtraction, multiplication, or division. New programmers trace text choices, numeric operands, and a zero-divisor guard.Open example →py# Menu-driven calculator print("1. Addition") print("2. Subtraction")
- 17Bill Discount SystemBeginnerTake one discount percentage off a Python bill. A beginner threshold exercise contrasts this policy with slabs and keeps negative amounts out of payment math.Open example →py# Program for bill discount system amount = float(input("Enter total bill amount: "))
- 18Login AuthenticationBeginnerRequire both demo credentials to match in a Python login decision. Beginners practice and and string equality without mistaking hardcoded text for real security.Open example →py# Simple login authentication USERNAME = "admin" PASSWORD = "secret123"
- 19Validate Password StrengthIntermediateCheck length and character groups with Python regex searches. This beginner password-policy exercise explains matches and why passing is not proof of safety.Open example →py# Program to validate password strength import re
- 20Validate Email FormatIntermediateTest an email-shaped string with Python regex and if. For new programmers, this example separates a rough formatting rule from a mailbox that actually exists.Open example →py# Program to validate email format using regex import re