0

Um, I'm actually KrazyKitsune, I'll use that account after I manage to recover my password.

So I'm having trouble with RS NOR latches. I did this:

s = int(raw_input("set Set value: "))
r = int(raw_input("set Reset value: "))
qi = not (s or q)
q = not (r or qi)
print q, qi

But the problem is...

If I do s = 1 and r = 0, it works fine and returns True (for Q) and False (for Q inverse). But if I do s = 0 and r = 1, it returns an error stating that the local variable 'q' was referenced before its assignment. I understand the error, but I don't know how to fix it.

If I switch qi = not (s or q) with q = not (r or qi), it becomes the other way around. s = 0 and r = 1 works, and s = 1 and r = 0 returns an error.

Any help?
And a note: I'm trying to use only boolean expressions.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by LogicallyInsane
0

This is latch circuit, I do not think it is possible to simulate by only boolean logic from basic input the way the circuit works. You should extract logic of function and code that as program.

That is my impression on information from net, I do not know this subject well.

You can of course use both logic equation versions in one program by placing the other one in except part of try statement containing the other version of code for that input, so if one of functions work the result is working.

s = int(raw_input("set Set value: "))
r = int(raw_input("set Reset value: "))
try:
    qi = not (s or q)
    q = not (r or qi)
except:
    q = not (r or qi)
    qi = not (s or q)
    
print q, qi

Edited by pyTony: n/a

0

Arigato Gozaimas, tonyjv, your answer will help me make the other latches and flip flops. So, thread closed.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.