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
#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


Messages In This Thread
RE: need help in conditional statement if else - by deanhystad - Mar-26-2020, 04:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Common understanding of output processing with conditional statement neail 6 2,056 Sep-17-2023, 03:58 PM
Last Post: neail
  Help with conditional statement SnekLover123 2 3,927 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