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

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.

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

I think the code should look like this

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)

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

does anyone know what the formula is

Maybe you should look at the python bit-wise operators in the Python Docs

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

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

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.

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

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

s = a ^ b and c = a & b