Given the following Boolean variables, what would be the output of the following statements? Python Data Handling
As found in PriP 1.2, Data Handling. Class 12 Computer Science with Python by Sumita Arora is referred to in schools affiliated to but not limited to CBSE.
Q10. Given the following Boolean variables, what would be the output of the following statements?
x = True
y = False
z = False
print(not x or y)
not x
→not True
→False
y
→False
Therefore,not x or y
→False or False
→False
Output:False
print(not x or not y and z)
not x
→not True
→False
not y
→not False
→True
z
→False
Now evaluatenot y and z
→True and False
→False
Therefore,not x or (not y and z)
→False or False
→False
Output:False
print(not x or y or not y and x)
not x
→not True
→False
y
→False
not y
→not False
→True
x
→True
Now evaluatenot y and x
→True and True
→True
Therefore,not x or y or (not y and x)
→False or False or True
→True
Output:True
print('ant' < 'amoeba')
The first character of both strings is'a'
, which is the same. The second character of'ant'
is'n'
, and the second character of'amoeba'
is'm'
.
Since'n'
has a higher ASCII value than'm'
,'ant'
is considered greater than'amoeba'
.
Therefore, the expression evaluates toFalse
.
Output:False
This statement compares two strings lexicographically, or in the way of dictionaries. So, in a lexicographic order, the comparison is done character by character based on their ASCII values.
Basically, you compare which word comes first like in a dictionary. So amoeba
would come first in a dictionary between the two.