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

4
Contributors
12
Replies
13
Views
7 Years
Discussion Span
Last Post by srk619
0

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

0

I think the code should look like this

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

Your formulas don't match the table in the wikipedia page (where True is 1 and False is 0)

0

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

0

ie try it all but it does work it keeps on give ... instead of results of o1, 02

0

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

0

i know that but how do you put all that in to code so that it displays the results of o1 and o2 that what im having problems with

0

o1 == Sum and 02 == Carry and A B are the inputs.

s = a ^ b and c = a & b

Reread about the bitwise operators in your book.

0

hey chaney44145 thanks alot for your help i was have some trouble with the operations as i am new to python thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.