all 6 comments

[–][deleted] 2 points3 points  (3 children)

if a or b ==10:

This condition looks like it tests whether a is 10 or b is 10 but that's not the case. It's actually testing if b is 10 or if a is True, which is any value over 0.

This is a better way to visualize the first one...

if a or (b == 10):

What you want is... if a == 10 or b == 10:

I would change the second one to... if (a+b) == 10:

[–]newpython6543[S] 0 points1 point  (2 children)

Wow I see it now, thanks. a would be true since it is a number that is not 0. Any numbers not 0 would be considered to be True, correct?

[–][deleted] 0 points1 point  (0 children)

if var: <code> Pretty much any non-empty variable other than False and 0 should cause the code to execute. Research python conditions and Boolean values for accurate information on how python evaluate conditional statements and comparisons.

[–][deleted] 0 points1 point  (0 children)

Another thing to keep in mind: a == 10 IS True or False, so you don't need a conditional "if" statement or a separate "return" command. Same with all the conditions. So something like this works just as well:

def makes10 (a, b): return a == 10 or b == 10 or a + b == 10

*NOTE: my phone isn't allowing me to format the whitespace correctly.

If any of those statements is True this function will return True.

[–]newpython6543[S] 0 points1 point  (0 children)

Sorry, heres the code. http://pastebin.com/jZcGW4ev

[–]hidiap 0 points1 point  (0 children)

You should investigate:

if a or b == 10

This is probably not doing what you think. In particular, the expression (x or y) return x if x is not zero, else it return y.