Check every condition in Python if else even if one evaluates to true

Jose Magana

Is there a way in Python to continue checking conditions of an if else statement if one evaluates to true? Here's my code:

status = True

  if pass_len(S) == False:
    print ('Password must be at least 6 characters long')
    status = False
  elif pass_upper(S) == False:
    print('Password must include upper case letters')
    status = False
  elif pass_lower(S) == False:
    print('Password must include lower case letters')
    status = False
  elif pass_nums(S) == False:
    print('Password must include digits.')
    status = False
  else:
    status = True

  return status

For example, if the password doesn't have an uppercase character or numbers, I'd like to print both messages, instead of just "Password must include upper case letters" and it ending right there. I tried getting around this by taking return out of each statement, but it didn't work. Any help is appreciated, thanks.

Padraic Cunningham

Don't use elif, using if will make sure the the condition is checked. elif will only be checked when the if statement evaluates to False

In [40]: foo = 3

In [41]: if foo == 3:
   ....:     print (foo)
   ....: if foo != 4:    
   ....:     print ("checked too")
   ....:     
3
checked too

status = True sets status to True already so just return status no need for an else

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Pointer null check evaluates to true even though it is not assigned a null value

From Dev

Or condition never evaluates to true

From Dev

Java: if and else returning true or false at every condition

From Dev

Why else block is executed even though if condition is true?

From Java

If condition evaluates to true in debugger/runtime but if block is not executed

From Dev

python 3.5 : if statement evaluates as true and does nothing, even if told to do something

From Dev

How to check single line if else if else condition in Python

From Dev

How to check single line if else if else condition in Python

From Dev

Python. Will TWO condition checked, If `ONE == True`?

From Dev

Query if else if else check true?

From Dev

Adding items to dictionary if condition is true, else dont - python

From Dev

python if-else statement returning true only for if condition

From Dev

[] == ![] evaluates to true

From Dev

How is a local variable created even when IF condition evaluates to false in Ruby?

From Dev

Is it possible to use if else condition true fetch from one table else another table?

From Dev

Posgtres CASE condition with SUM aggregation evaluates not needed ELSE part

From Dev

Posgtres CASE condition with SUM aggregation evaluates not needed ELSE part

From Dev

Else case running even if true (If/Else)

From Dev

Take elements while a condition evaluates to true (extending ElementArrayFinder)

From Dev

Do not understand why if condition evaluates to True when variable is integer

From Dev

skipping if{} even though the condition is true?

From Dev

'If' condition is true but 'else' is being executed

From Dev

Else statement runs even if the "if" statements are true in PHP

From Dev

Python: if item in list evaluates False even though the item exists

From Dev

If Else condition on python

From Dev

Python if and else print condition

From Dev

Avoiding if else condition in python

From Dev

Multiple else condition in python

From Dev

In C++ is it possible to write a lambda that is a condition i.e. just a condition that evaluates to true or false

Related Related

  1. 1

    Pointer null check evaluates to true even though it is not assigned a null value

  2. 2

    Or condition never evaluates to true

  3. 3

    Java: if and else returning true or false at every condition

  4. 4

    Why else block is executed even though if condition is true?

  5. 5

    If condition evaluates to true in debugger/runtime but if block is not executed

  6. 6

    python 3.5 : if statement evaluates as true and does nothing, even if told to do something

  7. 7

    How to check single line if else if else condition in Python

  8. 8

    How to check single line if else if else condition in Python

  9. 9

    Python. Will TWO condition checked, If `ONE == True`?

  10. 10

    Query if else if else check true?

  11. 11

    Adding items to dictionary if condition is true, else dont - python

  12. 12

    python if-else statement returning true only for if condition

  13. 13

    [] == ![] evaluates to true

  14. 14

    How is a local variable created even when IF condition evaluates to false in Ruby?

  15. 15

    Is it possible to use if else condition true fetch from one table else another table?

  16. 16

    Posgtres CASE condition with SUM aggregation evaluates not needed ELSE part

  17. 17

    Posgtres CASE condition with SUM aggregation evaluates not needed ELSE part

  18. 18

    Else case running even if true (If/Else)

  19. 19

    Take elements while a condition evaluates to true (extending ElementArrayFinder)

  20. 20

    Do not understand why if condition evaluates to True when variable is integer

  21. 21

    skipping if{} even though the condition is true?

  22. 22

    'If' condition is true but 'else' is being executed

  23. 23

    Else statement runs even if the "if" statements are true in PHP

  24. 24

    Python: if item in list evaluates False even though the item exists

  25. 25

    If Else condition on python

  26. 26

    Python if and else print condition

  27. 27

    Avoiding if else condition in python

  28. 28

    Multiple else condition in python

  29. 29

    In C++ is it possible to write a lambda that is a condition i.e. just a condition that evaluates to true or false

HotTag

Archive