Day 7 of Problem Solving Series In Python | Geethu Talks

Table of Contents
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
- 🔁
whileloop - 🔢 Counter variable (
attempts) - 🚩 Flag variable (
granted) - 🧩
and/notconditions
🧠 Step 1: Logic Build Cheddam
for loop lo count telusu. Ikkada entha sarlu avuthundo teliyadu, anduke while:
- Attempts 0 tho start
- Attempts 3 kanna takkuva and access raaledu aithe PIN adugu
- Prathi saari attempts 1 penchu
- PIN match ayithe stop; 3 attempts aipoyaka Card blocked
💡 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
| Code | Meaning |
|---|---|
attempts = 0 | Try count start |
while attempts < 3 and not granted | 3 attempts lopu and access raaka mundu repeat |
attempts = attempts + 1 | Prathi try ki count penchadam |
pin == correct_pin | Compare cheyadaniki == (rendu equal signs) |
if not granted | Loop 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
- ✔️
whileloop 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
Day 7 of Problem Solving Series Day 7 of Problem Solving Series Day 7 of Problem Solving Series Day 7 of Problem Solving Series


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