We want numbers that lie between 1 and 10 inclusive what is the truth table that we are expecting?

Thread Starter

terabaaphoonmein

Joined Jul 19, 2020
109
I know the answer, I need to use an OR gate because that is how the code works. I want to learn the problem solving part of this.

The code that works is:


Python:
  if(x<1 or x>10):
         print("Error")
    else:
         print("Ok")

Also and gate works if used differently. but I am unable to figure out the problem solving part of it. i.e figuring out how to decide what to use. that is what is confusing me. and this is very common thing in programming. very important as well.

I know the truth tables of OR and AND gate as well:



What are we expecting in output condition in this case?

I will explain it with a figure:



What is the condition we are expecting there? What is needed to be either true or false in output condition ? Can you clarify that much?


This is such a basic question but it is affecting my programming skills too much vividly. I am unable to figure out what condition are we trying to find in output?? I asked this question here as well, but didn't get my answer that I was trying to get.

https://electronics.stackexchange.c...ive-why-should-i-use-or-gate-in/596643#596643
 
Last edited:

Papabravo

Joined Feb 24, 2006
19,023
Let's talk about x & y as integers. We have a number of ways to test those integers to see if they are within a specific range. We also need to distinguish between the bitwise operators '&' and '|' and their relational counterparts '&&' and '||'. The result of using the relation operators is either TRUE or FALSE without any regard to how TRUE and FALSE are implemented.

We can write if(x>0 && x<11) which will be TRUE if x belongs to [1...10]
We get the identical result if we write if( ! (x<1 || x>10) ). This is actually a NOT OR or NOR operation. If you apply DeMorgan's law to the expression you will see that they are identical which is obvious from a truth table.
 

boostbuck

Joined Oct 5, 2017
226
Per Papabravo's explanation, the outputs missing from your unfinished table are generated by logical OR of the inputs, followed by an inversion (NOT) of the result. This process is a logical reversal of the comparisons, followed by a reversal of the result, which gives the same answer.

What you seem to be missing is a familiarity with DeMorgans Law : "The rules allow the expression of conjunctions and disjunctions purely in terms of each other via negation".
 
Top