Python basics – Day 05

Day 5 – Conditional Statements (if / elif / else)

Project: Create a “Smart Login & Grade Evaluator”

01. Learning Goal

By the end of this lesson, you will be able to:

Understand and use Python conditional statements

Combine compar…


This content originally appeared on DEV Community and was authored by Sabin Sim

Day 5 – Conditional Statements (if / elif / else)

Project: Create a “Smart Login & Grade Evaluator”

01. Learning Goal

By the end of this lesson, you will be able to:

  • Understand and use Python conditional statements
  • Combine comparison and logical operators in conditions
  • Build nested conditions for complex logic
  • Create a mini project that checks grades and simulates login

02. Problem Scenario

You are designing a Smart Evaluator App that decides different outcomes:

whether someone is an adult, what their grade is, and whether login credentials are correct.

03. Step 1 – Basic if Statement

A condition executes only when it is True.

age = 20

if age >= 18:
    print("You are an adult.")

⚠️ Indentation matters!
Python relies on consistent indentation (recommended: 4 spaces).

04. Step 2 – if ~ else

If the condition is true → run the if block.
If false → run the else block.

age = 15

if age >= 18:
    print("Adult")
else:
    print("Minor")

05. Step 3 – if ~ elif ~ else

Used for checking multiple conditions in sequence.
Python executes the first True condition only.

score = 85

if score >= 90:
    print("Grade A")
elif score >= 80:
    print("Grade B")
elif score >= 70:
    print("Grade C")
else:
    print("Grade F")

06. Step 4 – Nested if (Conditions within Conditions)

You can place one if statement inside another for more complex logic.

age = 20
is_student = True

if age >= 18:
    if is_student:
        print("Adult student.")
    else:
        print("Adult but not a student.")

07. Step 5 – Logical Operators in Conditions

You can combine multiple conditions using and, or, not.

temp = 25

if temp > 20 and temp < 30:
    print("The weather is warm.")

08. Step 6 – Practice Examples

Example 1: Even or Odd

num = int(input("Enter a number: "))

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

Example 2: Age Group Classifier

age = int(input("Enter your age: "))

if age < 13:
    print("Child")
elif age < 20:
    print("Teenager")
else:
    print("Adult")

Example 3: Login Simulation

user_id = input("Enter ID: ")
password = input("Enter password: ")

if user_id == "admin" and password == "1234":
    print("Login successful!")
else:
    print("Login failed!")

09. Step 7 – Mini Project: Smart Login & Grade Evaluator

Combine multiple conditions into one program that evaluates both login and performance.

user_id = input("Enter ID: ")
password = input("Enter password: ")

if user_id == "admin" and password == "1234":
    print("✅ Login successful!")
    score = int(input("Enter your score: "))

    if score >= 90:
        print("Excellent performance! Grade A")
    elif score >= 75:
        print("Good job! Grade B")
    elif score >= 60:
        print("You passed. Grade C")
    else:
        print("Failed. Try again next time.")
else:
    print("❌ Invalid credentials. Access denied.")

10. Reflection

You have learned how to:

  • Use conditional statements to control program flow
  • Combine logical and comparison operators
  • Apply nested conditions for complex decisions
  • Build a working Smart Evaluator program

In the next lesson, you’ll learn how to repeat actions automatically using loops (for, while) — the foundation of all automation and data processing tasks.


This content originally appeared on DEV Community and was authored by Sabin Sim


Print Share Comment Cite Upload Translate Updates
APA

Sabin Sim | Sciencx (2025-10-13T21:05:27+00:00) Python basics – Day 05. Retrieved from https://www.scien.cx/2025/10/13/python-basics-day-05/

MLA
" » Python basics – Day 05." Sabin Sim | Sciencx - Monday October 13, 2025, https://www.scien.cx/2025/10/13/python-basics-day-05/
HARVARD
Sabin Sim | Sciencx Monday October 13, 2025 » Python basics – Day 05., viewed ,<https://www.scien.cx/2025/10/13/python-basics-day-05/>
VANCOUVER
Sabin Sim | Sciencx - » Python basics – Day 05. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/10/13/python-basics-day-05/
CHICAGO
" » Python basics – Day 05." Sabin Sim | Sciencx - Accessed . https://www.scien.cx/2025/10/13/python-basics-day-05/
IEEE
" » Python basics – Day 05." Sabin Sim | Sciencx [Online]. Available: https://www.scien.cx/2025/10/13/python-basics-day-05/. [Accessed: ]
rf:citation
» Python basics – Day 05 | Sabin Sim | Sciencx | https://www.scien.cx/2025/10/13/python-basics-day-05/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.