Question

In: Computer Science

What is the result of the following statement? not 1 or 0 and 1 or 3...

What is the result of the following statement?

not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9

It is python logical operator (not, and, or)

I know the result is 4 by running the code, but I don't understand the logic behind it, can you explain it step by step? e.g. How to eliminate those numbers in each step to get the result.

Thanks

Solutions

Expert Solution

Explanation:

1)AND operation example:

How 3 AND 4 is 4:

AND operator gives priority to the right value of the expression and gives that number as the result provided neither side should have 0 other wise 0 will be printed, for e.g

3 and 4 is 4 since on the right side of the expression the value is 4 and no side is 0, had it 0 anyside then the result of the expression would jave also been 0.

4 AND 3 is 3 since right side contains 3 and no value is 0

4000 AND 3 is 3 since right side contains 3 and no value is 0

0 AND 4000 is 0 since one side contains 0

2)OR operation example:

How 3 OR 4 is 3:

OR operator gives priority to the left value of the expression and gives that number as the result provided neither side should have 0 other wise if any side contains 0 then the other number will be printed .

3 OR 4 is 3 since left side contains 3 and no value is 0

0 OR 3 is 3 since left side contains 0 then the other number would be printed

1 OR 500 is 1 since left side priority, it contains 1 on left side and no value is 0

3)NOT operation example:

NOT operation for any positive value greater than 0 or any negative value would give false i.e 0 and for the value 0 it will give true i.e 1

NOT 0 is true

NOt 100 is false

NOTE: If any OR comes in a expression then the whole right and left side are considered as a single expression i.e the above rules apply for long expression also

Given expression:not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9

not 1 or 0 is 0

not 1 or 0 and 1 is 0

not 1 or 0 and 1 or 3 is 3 since one side 0

not 1 or 0 and 1 or 3 and 4 is 4 since right side priority now all the expressions will be considred as two numbers as left and right since both and and or have already applied.

now, not 1 or 0 and 1 or 3 and 4 or 5 is 4 since left side priority, not 1 or 0 and 1 or 3 and 4 is considered as single number on left side, 5 is considered as single on right side

not 1 or 0 and 1 or 3 and 4 or 5 and 6 is also 4 since not 1 or 0 and 1 or 3 and 4 is one expression on left side , 5 and 6 is another single expression on right side

similarly for not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9, not 1 or 0 and 1 or 3 and 4 is one expression on left side , 5 and 6 or 7 and 8 and 9 is another single expression on right side.

Once one and and one or expression which is non-zero is achieved the total expression would then be considered as two one on left and one on right


Related Solutions

x is 5, what is the result of the following Boolean expressions: 1. x != 0  ...
x is 5, what is the result of the following Boolean expressions: 1. x != 0   2. x > 0   3. x != 0 4. x > 0 5. (x >= 0) || (x < 0) 6. (x != 1) == !(x == 1) 7. (true) && (3 > 4) True or False? Please explain how you got your answers. I've been struggling with Boolean expressions so I'd like a little bit more of an explanation as to why each...
Consider the following function: (?) = ?(?3 + 1), ? = 0, 1, 2, 3 What...
Consider the following function: (?) = ?(?3 + 1), ? = 0, 1, 2, 3 What is the value of the constant ? so that (?) is a pmf? Plug-in the value of ? in the expression of (?) and show the pmf in a table. Draw a probability histogram of the pmf. Find the cdf (?) and write it explicitly defined over the entire real number line. Draw the cdf (?). Calculate the probabilities: (i). (0 < ? ≤...
1. For the following statement, indicate whether what is described would result in an increase or...
1. For the following statement, indicate whether what is described would result in an increase or decrease in genetic diversity within population. a. Inbreeding due to a small population that is geographically isolated b. A 10,000 person population growing from the movement of 5,000 people into the population coming from another geographically isolated location. c. A catastrophic tsunami that drastically reduces the size of population. d. A small group of individuals from one population moving to a geographically distant site...
Consider the following vectors: →a = 5 −1 3 3 →b = 5 0 1 0...
Consider the following vectors: →a = 5 −1 3 3 →b = 5 0 1 0 →c = −10 3 −3 −7 For each of the following vectors, determine whether it is in span{→a, →b, →c}. If so, express it as a linear combination using a, b, and c as the names of the vectors above. →v1 = 5 −3 2 7 < Select an answer > →v2 = 2 7 6 −7 < Select an answer > →v3 =...
Consider the following reference string: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0,...
Consider the following reference string: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 Find the number of Page Faults with FIFO, Optimal Page Replacement, and LRU with four free frames that are initially empty. Which algorithm gives the minimum number of page faults?
Consider the following page reference string: 0, 1, 2, 3, 1, 0, 4, 5, 1, 0,...
Consider the following page reference string: 0, 1, 2, 3, 1, 0, 4, 5, 1, 0, 1, 2, 6, 5, 2, 1, 0, 1, 2, 5 How many page faults would occur for the following replacement algorithms, assuming one, three, five, and seven frames? Remember that all frames are initially empty, so your first unique pages will cost one fault each. Optimal replacement LRU replacement CLOCK replacement FIFO replacement
Consider the following page reference string: 0, 1, 2, 3, 1, 0, 4, 5, 1, 0,...
Consider the following page reference string: 0, 1, 2, 3, 1, 0, 4, 5, 1, 0, 1, 2, 6, 5, 2, 1, 0, 1, 2, 5 How many page faults would occur for the following replacement algorithms, assuming one, three, five, and seven frames? Remember that all frames are initially empty, so your first unique pages will cost one fault each. Optimal replacement LRU replacement CLOCK replacement FIFO replacement
3. In R4 , does the set {(1, 1, 1, 0,(1, 0, 0, 0),(0, 1, 0,...
3. In R4 , does the set {(1, 1, 1, 0,(1, 0, 0, 0),(0, 1, 0, 0),(0, 0, 1, 1)}, span R4? In other words, can you write down any vector (a, b, c, d) ∈ R4 as a linear combination of vectors in the given set ? Is the above set of vectors linearly independent ? 4. In the vector space P2 of polynomials of degree ≤ 2, find explicitly a polynomial p(x) which is not in the span...
eigenvalues of the matrix A = [1 3 0, 3 ?2 ?1, 0 ?1 1] are...
eigenvalues of the matrix A = [1 3 0, 3 ?2 ?1, 0 ?1 1] are 1, ?4 and 3. express the equation of the surface x^2 ? 2y^2 + z^2 + 6xy ? 2yz = 16. How should i determine the order of the coefficient in the form X^2/A+Y^2/B+Z^2/C=1?
Solve the following ODE using Laplace Transforms ?̈+?̇+3?=0;?(0)=1; ?̇(0)=2
Solve the following ODE using Laplace Transforms ?̈+?̇+3?=0;?(0)=1; ?̇(0)=2
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT