Simulating logic gates and circuits in Python