Guess the pattern

This is the first "Guess the Pattern" lesson. Use the tests below to find the pattern of the function my_function. This is a "reverse engineer process", where you don't have any guidelines, you just know what the function receives, and what the function returns.

Your job is to figure out the pattern and implement it in my_function.

Only for this first lesson, we'll provide more details; for the following ones you'll use only the tests.

Let's read the first test:

assert my_function(2) == 4

The way to "reverse" these functions is by understanding the Input and Output of the function, its interface.

  • The input of the function is a number: 2
  • The output is another number: 4

We don't know the internals of the function, that's what we need to figure out. But we can clearly see that, at least in this first example, what the function is doing is doubling the input number (2 > 4).

You can take it from here...

Test Cases

test your function - Run Test

def test_your_function():
    assert my_function(2) == 4
    assert my_function(3) == 6
    assert my_function(5) == 10
    assert my_function(9) == 18

Solution 1

def my_function(x):
    return x * 2
def my_function(x): pass