Guess the pattern

Use the test to guess the pattern used by the function and implement it using Python.

Hint: The abs python function might be handy ;)

Test Cases

test your function - Run Test

def test_your_function():
    assert my_function(2) == 4
    assert my_function(3) == 6
    assert my_function(-1) == 2
    assert my_function(-3) == 6

Solution 1

def my_function(x):
    return abs(x) * 2
def my_function(x): pass # Try the `abs` function # You can safely delete this code after you're done trying # It's not needed for your function print(abs(-9)) print(abs(9))