Python Forum
need help in conditional statement if else
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help in conditional statement if else
#1
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
Reply
#2
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.
Reply
#3
just to mention that if (user == 'abc') and (password == 'pass123'): doesn't need brackets
if user == 'abc' and password == 'pass123':
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
Thanks Guys
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Common understanding of output processing with conditional statement neail 6 887 Sep-17-2023, 03:58 PM
Last Post: neail
  Help with conditional statement SnekLover123 2 3,220 Sep-25-2017, 02:36 AM
Last Post: SnekLover123

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020