how to modify the following code so , print statements and input statements dont overlap…
- User
how to modify the following code so , print statements and input statements dont overlap with each other in terminal and stay in specific lines for example using terminal libraries like curses : import time import threading
def AND_Gate(a,b): return a and b def OR_Gate(a,b): return a or b def NOT_Gate(a): return not a def NAND_Gate(a,b): return not (a and b) def NOR_Gate(a,b): return not a and not b def XOR_Gate(a,b): return (a or b) and not (a and b) def XNOR_Gate(a,b): return not ((a or b) and not (a and b))
class DFlipFlop: def init(self): self.Q = False self.QN = True self.data = False def set_data(self, D): self.data = D def update(self): self.Q = self.data self.QN = NOT_Gate(self.Q)
state = False def clock(speed=1): global state cycle = 0 while True: time.sleep(1 / speed / 2) state = False print(f"State : False, Cycle : {cycle}",end="\r",flush=True) time.sleep(1 / speed / 2) state = True print(f"State : True , Cycle : {cycle}",end="\r",flush=True) cycle += 1
def user(): while True: pin_1 = input("Enter Pin 1 State : ") == "True" pin_2 = input("Enter Pin 2 State : ") == "True" storage.set_data(pin_1) if state: storage.update() if pin_2: print(storage.Q)
clock_thread = threading.Thread(target=clock , daemon=False) clock_thread.start() storage = DFlipFlop() user()
- Assistant