DEV Community

Cover image for pythoonzie DAY 8!
Bhartiprof
Bhartiprof

Posted on

pythoonzie DAY 8!

UMMM, ITNI HOLI KHELNE K BAAD FIRSE SHURU KARTE HAI YEH VLOG EPISODE ONE

SO HERE DRAMA IS ME GUYSS

Hey guys! Welcome back to the vlog. Today we’re testing a Python program that behaves like an ATM machine. The rule is simple: you only get three chances to enter the correct PIN. Let’s see how the logic works behind the scenes.

First, the program sets an attempt counter starting at 1. Then a while loop begins, which means the system will keep repeating the process as long as the attempts are less than or equal to three. Every time the loop runs, the ATM asks the user to enter a PIN.

Now here comes the interesting part. The program checks the PIN using an if condition. If the entered PIN is 1234, the system prints “valid” and immediately stops the loop using the break keyword. Think of break like an emergency exit door—it stops the loop instantly because the correct PIN has been entered.

But what if the user enters the wrong PIN? The program increases the attempt counter and checks another condition. If all three attempts are finished, the system prints “max attempts completed.” That means the ATM is basically saying, “No more tries, please step away from the machine.”

If the PIN is wrong but attempts are still left, the program simply prints “invalid attempt” and the loop runs again, giving the user another chance.

So in this small Python story, the while loop controls repetition, the if–elif–else statements check conditions, the counter variable tracks attempts, and the break keyword stops the loop when the goal is achieved.

And that’s the whole ATM challenge! Three attempts, one correct PIN, and Python handling everything like a smart little security guard.

ALSO I LEARNED ABOUT THE DIFFERENCE BETWEEN BREAK AND CONTINUE,

_- BREAK THAT SKIP A SINGLE ITERATION

  • CONTINUE THAT SKIP A PROPER LOOP STATEMENT_

#python #Day1 #DataScience #bhartiinsan

Top comments (0)