Course Content
Python Indentation, Comments and Variables
0/2
Object Oriented Programming in Python
0/1
Exception Handling in Python
0/1
Sending emails with Python
0/1
Unit test in python programming
0/1
Python programming (zero to advance!!!)
About Lesson

Boolean and

Define a function named triple_and that takes three parameters and returns True only if they are all True and False otherwise.

 

==== SOLUTION ====

You can implement the `triple_and` function in Python by using the logical AND (`and`) operator to check if all three parameters are `True`. Here’s how you can do it:

“`python
def triple_and(a, b, c):
      # Check if all three parameters are True
      return a and b and c

# Test the function
print(triple_and(True, True, True)) # Output: True
print(triple_and(True, False, True)) # Output: False
print(triple_and(False, False, False)) # Output: False
“`

Explanation:

1. `def triple_and(a, b, c):`: This line defines a function named `triple_and` that takes three parameters `a`, `b`, and `c`.

2. `return a and b and c`: This line uses the logical AND (`and`) operator to check if all three parameters `a`, `b`, and `c` are `True`. If all are `True`, it returns `True`; otherwise, it returns `False`.

So, when you call `triple_and(True, True, True)`, it returns `True` because all three parameters are `True`. Similarly, for `triple_and(True, False, True)`, it returns `False` because not all parameters are `True`. And for `triple_and(False, False, False)`, it also returns `False` because none of the parameters are `True`.

 

Join the conversation