0
¿how I can stop after an "else"?
how can I stop the code or have it return to the same action after an "else"? since the objective of what I did is a page from a bank but it is assumed that when the password was wrong, it stopped or restarted any help please P.D: I recommend using a separate compiler to see the error as a spyder and not speak English well https://code.sololearn.com/cP8MT8qfZBB5/?ref=app
3 ответов
+ 7
You can do
if password != "79075":
# access denied
else:
# opening bank
# welcome etc
By grouping it this way, the remainder of the program will not be performed should the password be wrong.
If you want to give the user a few attempts to get the password correct, then you'll need a loop for that.
+ 8
Another way:
login = password == "79075"
if login:
print ("opening the bank")
else:
print ("Access Denied")
if login:
print ("Welcome to your Status\nWhat do you want to see?")
(...)
Note that any solution like this would be highly insecure in real life 😶
https://code.sololearn.com/czJn3Pi3kUgm/?ref=app
+ 2
https://code.sololearn.com/cq0r8bsw79X9/?ref=app this code doesn't work in St playground but it works fine on my local installation. this is just to show you how to restart from a point if your requirements are not met using loop...