1
Hatchling0 / 300 XP
0day streak 0stars
Your Python practice
Mock tests Readiness
More
Guest mode · saved on this device.

The solution() function

In a CodeSignal single-function question you are handed a function to complete. The tests call it with their inputs and look at what it returns. Nothing you print is graded.

def solution(minutes):
    return minutes // 60    # the tests see this value

Three rules for every exercise from here on:

  • The inputs arrive as parameters. Never ask for them with input().
  • The answer leaves with return. print shows text to you, and the function hands back None.
  • Keep the name and parameters you were given. The tests call them exactly.

Here, Run samples tries the visible tests. Submit also runs hidden tests, which you only see as a count. Fix what fails, run again; you can submit as often as you like.

The real assessment is graded against hidden tests too, so this loop is the one to practise.

See it run

def solution(a, b):
    return a * b

answer = solution(6, 7)
print(answer)

A function is defined first, then called. Watch what the call hands back.

Practice the solution() function

Exercise 1

Write solution(minutes) that returns the number of whole hours in minutes. For example, solution(130) is 2. minutes is zero or more.

Exercise 2

Write solution(first, last) that returns the name as "Last, First". For example, solution("Ada", "Lovelace") is "Lovelace, Ada".

Exercise 3

Write solution(a, b, c) that returns the middle of three numbers: the one that is neither the smallest nor the largest. If two are equal, that value counts as the middle. For example, solution(3, 1, 2) is 2 and solution(5, 5, 1) is 5.

Free lesson: use the editor to practice it.

Practice

Loading Python…
More
Loading exercise content…
Visualizer Watch your code run line by line

Run your code, then choose Play to follow its execution.

Memory · names → values
Variables appear here as Python creates them.
Output & plots

One-line daily quest