Linked Questions

Popular Questions

Im trying this excercise on Codebat:

Given a number n, return True if n is in the range 1..10, inclusive. Unless outside_mode is True, in which case return True if the number is less or equal to 1, or greater or equal to 10.

Code 1 :

def in1to10(n, outside_mode):
  if not outside_mode:
      return  n in range(1,11)
  return n <= 1 or n >= 10 

Code 2:

def in1to10(n, outside_mode):
  if outside_mode and  n <= 1 and n >= 10:
    return True
  elif n >= 1 and n <= 10:
    return True
  else:
    return False

Can somebody explain this to me, because i think these codes are quite similiar.

Related Questions