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: srk619 is an unknown quantity at this point 
Solved Threads: 0
srk619 srk619 is offline Offline
Light Poster

implementing half adder in python help

 
0
  #1
Mar 30th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 984
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 222
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Posting Shark

Re: implementing half adder in python help

 
0
  #2
Mar 30th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 40
Reputation: srk619 is an unknown quantity at this point 
Solved Threads: 0
srk619 srk619 is offline Offline
Light Poster

Re: implementing half adder in python help

 
0
  #3
Mar 30th, 2009
so the coding should look something like this:

i1= True
2 i2= False
3 o2 = i1+i2
4 o1 = i1-i2

is that wrong also how does it print the o1 and o2 with results
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 984
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 222
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Posting Shark

Re: implementing half adder in python help

 
0
  #4
Mar 30th, 2009
I think the code should look like this
  1. def half_adder(i1, i2):
  2. o1 = # put your formula here
  3. o2 = # put your formula here
  4. return o1, o2
Your formulas don't match the table in the wikipedia page (where True is 1 and False is 0)
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 40
Reputation: srk619 is an unknown quantity at this point 
Solved Threads: 0
srk619 srk619 is offline Offline
Light Poster

Re: implementing half adder in python help

 
0
  #5
Mar 30th, 2009
ive look at the table

A half adder has 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.

so i1 and i2 will give o1
i1 or i2 will give o2

so how do i write that as a formula
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 40
Reputation: srk619 is an unknown quantity at this point 
Solved Threads: 0
srk619 srk619 is offline Offline
Light Poster

Re: implementing half adder in python help

 
0
  #6
Mar 31st, 2009
does anyone know what the formula is
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 638
Reputation: Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough 
Solved Threads: 103
Murtan Murtan is offline Offline
Practically a Master Poster

Re: implementing half adder in python help

 
0
  #7
Mar 31st, 2009
Maybe you should look at the python bit-wise operators in the Python Docs
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 40
Reputation: srk619 is an unknown quantity at this point 
Solved Threads: 0
srk619 srk619 is offline Offline
Light Poster

Re: implementing half adder in python help

 
0
  #8
Mar 31st, 2009
ie try it all but it does work it keeps on give ... instead of results of o1, 02
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 40
Reputation: srk619 is an unknown quantity at this point 
Solved Threads: 0
srk619 srk619 is offline Offline
Light Poster

Re: implementing half adder in python help

 
0
  #9
Mar 31st, 2009
can some plz show me what the formula is to put in the code

def half_adder(i1, i2): o1 = # put your formula here o2 = # put your formula here return o1, o2

i really dont get it
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 10
Reputation: chaney44145 is an unknown quantity at this point 
Solved Threads: 1
chaney44145 chaney44145 is offline Offline
Newbie Poster

Re: implementing half adder in python help

 
0
  #10
Apr 1st, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum


Views: 795 | Replies: 12
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC