Ad
  • Custom User Avatar

    Wow, this is actually an incredibly helpful (yet simple) explanation! Thank you so much

  • Custom User Avatar

    On Codewars, you need to write functions that need to return the wanted values. Printing to console is useful if you personally want to read the result, but the rest of the program can't do anything with it.
    Functions are called to perform certain actions. In many cases, you want a function to simply perform a task and return a result back so that the program can use that result for futher calculations.

    A return command stops the current function and returns the values back to the function that called it.

    An example for a function that uses the return value of another function:

    def add(a,b):
      return a + b
      
    def increase_by_two(a):
      return add(a, 2)
      
    print(increase_by_two(5)) #prints 7 to the console
    

    If you run a function that does not print to console in your IDE, it might work, but you won't see any results. If you want to check the result of your function for a certain input, use print(count_sheep(3)) after your function (not inside it).

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution