DEV Community

Cover image for Now I’m curious… are they from your past or your present?
Tahami AK SERVICES
Tahami AK SERVICES

Posted on

Now I’m curious… are they from your past or your present?

🧾 Content:

Hey everyone,

I’m currently learning Python and practicing basic functions + if/else logic. I tried to build a simple login system, but I’m stuck on a small issue that’s confusing me.

Here’s what’s happening:
Even when I enter the wrong username, the program still asks for the password.

But logically, I want it to stop right there if the username is incorrect.

Here’s my code:

def login(username, password):
if username == "Admin" and password == 1234:
print("Login Successful")
return True
else:
print("Invalid Credentials")
username = input("Enter the username: ")
password = int(input("Enter the password: "))
if username == "Admin" and password == 1234:
print("Login Successful")
return True
else:
print("Invalid Credentials")
return False

My question is:
👉 How can I structure this so that the program only asks for the password after confirming the username is correct?

I feel like I’m mixing the logic somewhere, but I want to understand the correct approach instead of just copying a solution.

Would really appreciate a simple explanation 🙌

Also curious how did you guys structure your first...Read More

Top comments (0)