Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Formatting Code
#1
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.

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
Reply


Messages In This Thread
Formatting Code - by zeaky3000 - May-11-2018, 05:53 AM
RE: Formatting Code - by buran - May-11-2018, 06:12 AM
RE: Formatting Code - by ThiefOfTime - May-11-2018, 06:16 AM
RE: Formatting Code - by Larz60+ - May-11-2018, 06:24 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020