Challenge - Implement RS flip-flop logic using if statement and variables
Skills Required
- Setup python development environment
- Basic Printing in Python
- Commenting in Python
- Managing Variables in python
- Boolean and Logical Operations on variables in Python
- ‘if’, ‘else’, ‘elif’ condition in python
Please make sure to go through all the skills mentioned above to understand and execute the steps mentioned below
Truth table of RS flip-flop
In order to implement an RS flip-flop, we need to implement its truth table
Python implementation of RS flip-flop
- We will use 4 variables to store and manipulate the values of 2 inputs, current state and next state
# storing initial states and inputs in variables
inp1 = 0
inp2 = 1
prevState = 1
nextState = None
# RS flip-flop truth table implementation
if inp1==0 and inp2==0:
nextState = prevState
elif inp1==0 and inp2==1:
nextState = 0
elif inp1==1 and inp2==0:
nextState = 1
else:
print('Invalid input provided')
nextState = None
if nextState != None:
print("The next state is {0}".format(nextState))
else:
print("Unable to produce next state, please provide valid inputs and states...")
print("Execution complete...")
- Run the code using menu Run -> Run Without Debugging
- You should see the following output
The next state is 0
Execution complete...
You can also change the variable values and execute to see different outputs printed in the console
Video
The video for this post can be found here
Comments
Post a Comment