🏠 Home / Hub

🔀 Python Lesson 03 — Conditions & Loops

← Back to Python Menu

1. if / elif / else

mark = 75

if mark >= 80:
    print("Grade A")
elif mark >= 60:
    print("Grade B")
elif mark >= 40:
    print("Grade C")
else:
    print("Fail")

2. Comparison & Logical Operators

age = 20
has_nrc = True

print(age >= 18)          # True
print(age != 18)          # True
print(age >= 18 and has_nrc)
print(age < 18 or has_nrc)
print(not has_nrc)
and က နှစ်ခုလုံး true ဖြစ်ရမယ်။ or က တစ်ခု true ရင်ရတယ်။

3. for Loop

students = ["Aung", "Su", "Hla"]

for student in students:
    print(student)

for i in range(1, 6):
    print(i)  # 1 to 5

4. while Loop

count = 1

while count <= 5:
    print(count)
    count += 1

အကြိမ်အရေအတွက်မသေချာဘဲ condition ပြည့်နေသရွေ့ run ချင်ရင် while သုံးတယ်။

5. break / continue

for n in range(1, 10):
    if n == 5:
        break
    print(n)

for n in range(1, 6):
    if n == 3:
        continue
    print(n)

6. Practical Example

password = "admin123"

for attempt in range(3):
    user_input = input("Password: ")
    if user_input == password:
        print("Login success")
        break
    else:
        print("Wrong password")
else:
    print("Account locked")

📌 Study Checklist