Python Basics Q&A - 2

#Q1.What are the two values of the Boolean data type? How do you write them?
#Ans
'''
There are 35 keywords in Python among them only three are case-sensitive keywords and two of them are boolean so we write them as True and False.
'''
#Program to print boolean data type
a = 1
b = 0
print(bool(a))
print(bool(b))

#Result 
#True
#False
#Q2.What are the three different types of Boolean operators?
#Ans
'''
Boolean Operations are simple arithmetic of True and False values. These values can be manipulated by the use of boolean 
operators which include AND, Or, and NOT
'''
#A program to check these operators
a = True
b = False

x = a and b
y = b or a 
z = not b
print(x,y,z)

#Result
#False True True

This is the Truth Table for Boolean operators

#Q3. Make a list of each Boolean operator's truth tables (i.e. every possible combination of Boolean values for the operator and what it evaluates)
#Ans
'''
There are three different types of boolean operators OR, AND, NOT. So we will see each condition in the truth table 
Let's consider variables a and b. Now we see what operators do.
1. OR operator always selects True until and unless both the conditions are not False.
2. AND Operator Selects True if both the conditions are the same otherwise it selects False.
3. NOT operator returns an opposite value; if A is True, then NOT A is False.

#Truth Table
1. OR
 A        B      X
True	True	True
True	False	True
False	True	True
False	False	False

2. AND
 A        B       x
True	True	True
True	False	False
False	True	False
False	False	False

3. NOT
A       Not A
True	False
False	True
'''

Boolean expressions examples
 
'''
#Q4. What are the values of the following expressions?
(5 > 4) and (3 == 5)
not (5 > 4)
(5 > 4) or (3 == 5)
not ((5 > 4) or (3 == 5))
(True and True) and (True == False)
(not False) or (not True)
'''
#Ans
'''
To check this we need to make a variable for each expression so that we can check the result of the boolean data type.
False False True False False True
'''
#A Program to check these expressions
a= (5 > 4) and (3 == 5) # False
b= not (5 > 4) # False
c= (5 > 4) or (3 == 5) #True
d= not ((5 > 4) or (3 == 5)) #False
e= (True and True) and (True == False) #False
f= (not False) or (not True) #True

print(a,b,c,d,e,f)

#result
#False False True False False True

Six comparison operators

 
#Q5. What are the six comparison operators?
#Ans
'''
In Python, we often want to compare a value with another value. To do that, we use comparison operators.
Python has six comparison operators, which are as follows:
1. Less than ( < )
2. Less than or equal to (<=)
3. Greater than (>)
4. Greater than or equal to (>=)
5. Equal to ( == )
6. Not equal to ( != )
These comparison operators compare two values and return a boolean value, either True or False.
'''
#To Print a program that shows the logic of these operators
#1. Less than ( < )
a = 2
b = 5
print(a<b)

#2. Less than or equal to (<=)
a = 50
b = 49.9
print(a<=b)

#3. Greater than (>)
a = 10
b = 7
print(a>b)

#4. Greater than or equal to (>=)
a = 15
b = 15.6
print(a>=b)

#5. Equal to ( == )
a = 99.999
b = 99.999
print(a==b)

#6. Not equal to ( != )
a = 9
b = 9
print(a!=b)

#result
#True
#False
#True
#False
#True
#False
Next Post Previous Post