Can someone please explain to me the difference between the following two examples and why the shorter one compiles correctly and the longer one doesn't? Don't they both say the same thing? Forgive me, I'm new to coding!
The number 6 is a truly great number. Given two int values, a and b, return True if either one is 6. Or if their sum or difference is 6. Note: the function abs(num) computes the absolute value of a number.
The number 6 is a truly great number. Given two int values, a and b, return True if either one is 6. Or if their sum or difference is 6. Note: the function abs(num) computes the absolute value of a number.
def love6(a, b): return a == 6 or b == 6 or (a + b) == 6 or abs(a - b) == 6 #passes all tests
def love6(a, b): if a == 6 or b == 6: return True if (a + b) == 6 or abs(a - b) == 6: return True #Doesn't pass