Python Forum

Full Version: need help in conditional statement if else
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi need your help regarding if else function
here is my code
whatever id pass i put its make true and i use AND to check user and password sametime if true then go otherwise make it false but it make it true can you help me where i am mking mistake i am new to python no other lang have idea

user = input("type your Username ?")
password =input("type your password please ? ")
if(user == "abc", 'AND' ,password =="pass123"):
    print("welcome ", user, "hope you are doing fine")
    print("Note : Please must signin in 5 days a week ")
elif(user == "type" ,'AND', password=="type2"):
     print("welcome ", user, "hope you are doing fine")
     print("Note :", user, " Please must signin in 5 days a week ")
elif(user == "typeabc" ,'AND', password=="low"):
     print("welcome ", user, "hope you are doing fine")`enter code here`
     print("Note :",user, " Please must signin in 5 days a week ")
else:
    print("sorry cant find user")
thanks in advance
Your first if statement should look something like this:
if (user == 'abc') and (password == 'pass123'):
    print('Welcome', user, 'hope you are doing fine')
Note that single or double quotes can be used and the parenthesis in the if statement are only provided for clarity.

Your if statement is checking if a tuple is empty. If we assume neither the user or password match, the two statements below are equivalent and they are always True.
if (user =='abc', 'AND', password=='pass123'):
if (False, 'AND', False):
When using a tuple in an if statement like that:
if (): # is False
if (anything): # is True
Your tuple will always have three values, so it will always be true.

I think you need to read some of the python language documents.
just to mention that if (user == 'abc') and (password == 'pass123'): doesn't need brackets
if user == 'abc' and password == 'pass123':
Thanks Guys