| | |
implementing half adder in python help
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Mar 2009
Posts: 40
Reputation:
Solved Threads: 0
hi,
im having difficulty with this python question as i am new to python.
the question is:
Draw up the list of possible inputs for a half adder and the
outputs that you expect. Implement a half adder in a few lines of python, so that the
variables o1 and o2 are based on i1 and i2.
i1= True
2 i2= False
3 ............................
o1 =?
5 o2 =?
now i know the function should be something like this :h(i1, i2) =>o1, o2
im having difficulty with this python question as i am new to python.
the question is:
Draw up the list of possible inputs for a half adder and the
outputs that you expect. Implement a half adder in a few lines of python, so that the
variables o1 and o2 are based on i1 and i2.
i1= True
2 i2= False
3 ............................
o1 =?
5 o2 =?
now i know the function should be something like this :h(i1, i2) =>o1, o2
In this wikipedia page, you have a description of a half adder I think A, B, C, S are your variables i1, i2, o1, o2. There is a table showing all possible inputs and outputs.
Last edited by Gribouillis; Mar 30th, 2009 at 10:57 am.
I think the code should look like this
Your formulas don't match the table in the wikipedia page (where True is 1 and False is 0)
python Syntax (Toggle Plain Text)
def half_adder(i1, i2): o1 = # put your formula here o2 = # put your formula here return o1, o2
•
•
Join Date: May 2008
Posts: 638
Reputation:
Solved Threads: 103
Maybe you should look at the python bit-wise operators in the Python Docs
•
•
Join Date: Apr 2009
Posts: 10
Reputation:
Solved Threads: 1
Look at http://en.wikipedia.org/wiki/Adder_(electronics), what you are trying to code is two inputs, generally labelled A and B, and two outputs, the sum S and carry C.
S is the two-bit XOR of A and B, and C is the AND of A and B.
S is the two-bit XOR of A and B, and C is the AND of A and B.
![]() |
Other Threads in the Python Forum
- Previous Thread: wxpython tooltip
- Next Thread: Sendmessage|postmessage
Views: 795 | Replies: 12
| Thread Tools | Search this Thread |
Tag cloud for Python
abrupt apache application argv beginner binary book calculator change cipher code command converter dictionaries dictionary dynamic event examples excel file float format ftp function google gui homework import inches input java keyboard launcher line linux list lists loop maze microphone mouse movingimageswithpygame newb number numbers obexftp output parsing path permissions phonebook plugin port prime program programming projects py2exe pygame pyglet pyqt python random recursion recursive refresh remote scrolledtext search session signal simple ssh string strings strip table terminal text thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 valueerror variable verify vigenere windows wordgame wxpython xlwt





