Checking Multiple Boolean at a time

By | 14th June 2021

Let us take a real-time example of the banking system. The bank wants to offer a loan only to the active premium customers who are not on the defaulter’s list. For this, we are using the following code in python.

Method: 1

isActive,isPremium,isDefaulter=1,1,0
if isActive==1 and isPremium==1 and isDefaulter==1:
    print('Eligible for Loan')
else:
    print('Not Eligible')
Output:
Not Eligible

Method: 2

In this example, if the bank gives a loan to the customer which are all is an active premium and also the defaulter, the code we write as,

isActive,isPremium,isDefaulter=1,1,0
if isActive==1 or isPremium==1 or isDefaulter==1:
    print('Eligible for Loan')
else:
    print('Not Eligible')
Output:
Eligible for Loan

Method: 3

In the below methods, if any one of the options is true, we use the following codes.

isActive,isPremium,isDefaulter=1,1,0
if 1 in (isActive,isPremium,isDefaulter):
    print('Eligible for Loan')
else:
    print('Not Eligible')
Output:
Eligible for Loan

Method: 4

isActive,isPremium,isDefaulter=1,1,0
if any ((isActive,isPremium,isDefaulter)):
    print('Eligible for Loan')
else:
    print('Not Eligible')
Output:
Eligible for Loan