Day 7 of Problem Solving Series In Python

Day 7 of Problem Solving Series In Python | Geethu Talks

Day 7 of Problem Solving Series

Day 7 of Problem Solving Series

👋 Hi friends! Geethu Talks ki welcome. ATM lo 3 attempts tarvatha card block avuthundi. Idi Python lo ela chestham? ee roju while loop tho chuddam.

🎬 Reel chudaledha? Instagram / YouTube lo @GeethuTalks ni follow avvandi.

🧩 Real-life Problem

ATM lo PIN enter chesthunnaru. Correct PIN ayithe access, lekapothe maximum 3 attempts varaku try cheyyochu.

📋 Task: PIN match ayye varaku leda 3 attempts aipoye varaku PIN adagandi. Last lo Access granted leda Card blocked print cheyyandi.
📥 Sample input: 1111, 2222, 1234 (correct PIN = 1234)
📤 Sample output: Access granted

📚 Concepts Covered

  • 🔁 while loop
  • 🔢 Counter variable (attempts)
  • 🚩 Flag variable (granted)
  • 🧩 and / not conditions

🧠 Step 1: Logic Build Cheddam

for loop lo count telusu. Ikkada entha sarlu avuthundo teliyadu, anduke while:

  1. Attempts 0 tho start
  2. Attempts 3 kanna takkuva and access raaledu aithe PIN adugu
  3. Prathi saari attempts 1 penchu
  4. PIN match ayithe stop; 3 attempts aipoyaka Card blocked
attempts < 3 and not granted → keep asking

💡 Analogy: while ante security guard: condition true unnantha sepu lopaliki rau, condition false ayyaka aagipothadu.

💻 Step 2: Python Code

correct_pin = "1234"
attempts = 0
granted = False

while attempts < 3 and not granted:
    pin = input("Enter PIN: ")
    attempts = attempts + 1
    if pin == correct_pin:
        granted = True
        print("Access granted")
    else:
        print(f"Wrong PIN. Attempts left: {3 - attempts}")

if not granted:
    print("Card blocked")

✅ Output
Enter PIN: 1111
Wrong PIN. Attempts left: 2
Enter PIN: 2222
Wrong PIN. Attempts left: 1
Enter PIN: 1234
Access granted

🔍 Line by line


CodeMeaning
attempts = 0Try count start
while attempts < 3 and not granted3 attempts lopu and access raaka mundu repeat
attempts = attempts + 1Prathi try ki count penchadam
pin == correct_pinCompare cheyadaniki == (rendu equal signs)
if not grantedLoop aipoyaka card block message

⚠️ Common Mistake Alert

❌ Wrong: attempts + 1 marchipothe loop ela aagadu (infinite loop!)

attempts = 0
while attempts < 3:
    pin = input("Enter PIN: ")
    # attempts never increases, so the loop never stops!

✅ Right: Loop lopala condition ni marche line (attempts = attempts + 1) undali.

💡 Bonus tip: = value store chestundi, == compare chestundi. if pin = correct_pin rasthe error vasthundi.

📝 Quick Recap

  • ✔️ while loop condition true unnantha sepu repeat avuthundi
  • ✔️ Counter tho attempts track chesam
  • ✔️ Loop ni stop cheyadaniki condition marali

🏋️ Practice Problems

🟢 Easy: Password ‘python’ correct ga enter chesevaraku adugutune undandi. Correct aithe ‘Welcome!’ print cheyyandi.
Input: java, c, python → Output: Welcome!


🟡 Medium: Oka number lo digits sum cheyyandi (hint: % 10 and // 10).
Input: 345 → Output: 12


🔴 Challenge: Secret number 7. User 5 attempts varaku guess cheyyali. Prathi saari ‘Too low’ / ‘Too high’ / ‘Correct!’ print cheyyandi.
Input: 3, 9, 7 → Too low, Too high, Correct!


💬 Mee answers comments lo share cheyyandi!

🚀 Next: Day 8 – Instagram Username Check

Follow @GeethuTalks and stay tuned! 💛

⬅️ Previous: Day 6 of Problem Solving Series In Python

check out our website for more resources

1 thought on “Day 7 of Problem Solving Series In Python”

Leave a Comment