Why is my code wrong?

1 Like


I had a quick look at your function.
First thing is you have and else statement indented, without finishing the if statement, which will throw an error.
Secondly your function doesn’t test the arguments that are passed in, that is expression1 and expression2, it tests the values True and False instead.

What you want to do is test the expressions, expression1 and expression2. If either of expression1 or expression2 is True, then it should return True.

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for understanding.

Noted! Thanks for that. Totally misunderstood whether they wanted help solving the entire problem or just the one answer to their question.

Your heart was in the right place.

Lets have a look at the logic behind the and, as well as the logic behind the or. I know, you’ve been through this many times over, but trust me, you overlooked this scenario and many others, had you not, you’d know how to build an cpu from scratch already.

With the and logic, we see that three of the four base scenarios result in False, with the remaining one resulting in True.

Note: I progressed up in the manner of counting up in binary.

0 and 0 = 0
0 and 1 = 0
1 and 0 = 0
1 and 1 = 1

Lets compare this to the or logic table.

0 or 0 = 0
0 or 1 = 1
1 or 0 = 1
1 or 1 = 1

Notice that the or logic has the opposite count of results, a single False and three True’s. Hey! I know, that’s what the not does, it flips the bits, I mean, the logic. Lets try it.

not( 0 and 0) = 1
not(0 and 1) = 1
not(1 and 0) = 1
not(1 and 1) = 0

But flipping the result of the and doesn’t equate to the or!? All it did was give us the same count of Truth’s and False’s! But that’s definitely a step closer, only if there were some way we could flip the values from the top to the bottom, but keep the same number of Truths. Let’s try something else.

not(0) and not(0) = 1
not(0) and not(1) = 0
not(1) and not(0) = 0
not(1) and not(1) = 0

That didn’t work, we’re back to where we started, except that, hey wait a minute, using not on both sides just flipped us from top to bottom. Is this right, is it possible? Using not on the entire statement flips the truth table to the opposite, and using not on each parameter flips it top to bottom. Lets put these tools on our tool belt for later, and lets give them a shot together to see if we get the desired outcome. To recap, we want the order from the top of the table to the bottom to have the values, (false, true, true, true), exactly the same as the or table. In this example, we are going to evaluate each step on a sinle line with the starting position on our left and the final outcome on our right.

not( not(0) and not(0) ) == not( 1 and 1) == not( True) == False
not( not(0) and not(1) ) == not( 1 and 0) == not( False) == True
not( not(1) and not(0) ) == not( 0 and 1) == not( False) == True
not( not(1) and not(1) ) == not( 0 and 0) == not(False) == True

That’s exactly what I was looking for, (F, T, T, T). Note, if you were doing this in electronics, be aware that a not is just grounding out before a transistor so the value is False instead of True, then a True becomes a False, so chaining nots and ands to create an or wouldn’t be ideal, because an or is simply two sources coming into one in parallel, if either is one then it gets power. But doing these kinds of exercises will teach you higher order logic like exclusive or, a latch, a half-adder, and a full-adder by combining your nots, ands, and or.

So, to recap.
The table was structured in the same order of counting from 0 up, but in binary.


Not on the entire table flipped (inverted) the entire table.
Not on each element in each row for each row, reversed the order from top to bottom.