Python: Testing Sets of Conditions

  1. Introduction to Python
  2. Python: Choosing a Text Editor or IDE
  3. Python: Hello World
  4. Python: Variables, Strings and Numbers
  5. Python: Variable Naming
  6. Python: Math, Familiar
  7. Python: Math, Less Familiar
  8. Python: Mathematical Order of Operations
  9. Python: Introducing PEP 8
  10. Python: Text Concatenation
  11. Python: if Statements and Comparison Operators
  12. Python: else and elif statements
  13. Python: Testing Multiple Conditions
  14. Python: Testing Sets of Conditions
  15. Python: Nested if Statements
  16. Python: Lists
  17. Python: Adding To and Changing Lists
  18. Python: Lists: Take a Slice, Delete Elements, Popping Elements
  19. Python: Tuples
  20. Python: for Loops
  21. Python: Nested for Loops
  22. Python: Capturing and Formatting User Input
  23. Python: Dictionaries
  24. Python: Functions
  25. Python: While Loops
  26. Python: Data Files
  27. Python: Using Pexpect
  28. Python : Using Pexpect :
  29. Python : Using Pexpect:
  30. Python: DCL Conversion to Python

Go to Chapter 12 of A Smarter Way.

What do you do if a test needs to meet two conditions at once? (Is this person both a Person and a Friend?)

This is where the keywords and and or come into play.

if student_count > 10 and chairs_count <= 10:
    print("Somebody's going to be standing.")

You can use more than one and orĀ or in the test:

if (doughnuts == 12 or crullers == 12)and coworkers_count <= 12:
    print("Everybody gets a goodie.")

Use parens to establish order of operations.



  1. Continue editing
  2. Create one example of a single and test, and one example of a single or test.
  3. Create one example of a test that involves more than one and or or.