Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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

Status
Not open for further replies.

shivajikobardan

Junior Member level 2
Joined
Oct 23, 2021
Messages
24
Helped
0
Reputation
0
Reaction score
2
Trophy points
3
Activity points
292
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:

e68IX.png


What are we expecting in output condition in this case?

I will explain it with a figure:

6rr9O.png


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.

 
Last edited:

Hi,

try an AND instead of OR:

if(x>=1 AND x<=10):

What happens? Does it work?
****

With the OR you focus on the WRONG values. Values <1 are wrong and values >10 are wrong.

With the AND you focus on the CORRECT values. Values >= 1 are correct and values <=10 are correct (only when both are true).

Klaus
 

In this case the symbols < > are a convenience. They allow us to condense a long chain of 'equals' statements. Internally each comparison yields a result of either 0 or -1.
We convert this to an output by creating a flag variable and setting it to a value we can use.

Example:

Code:
Let flag$="F" `set a default value
if x=1 then flag$="T"
if x=2 then flag$="T"
...etc.
if x=10 then flag$="T"
If flag$="T" then print "Ok" else print "Error"
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top