Function arguments

We're going to explore how to receive parameters and operate with them in your functions. In the editor you'll see a simple function that accepts just one parameter (named x in this case). This function's job is to multiply x by 2 and return the result. For example, if we pass 3 as the parameter, we're going to receive 3 * 2 as the result:

multiply_by_two(3)  # 6

Parameters are matched by position. In this case multiply_by_two receives only one parameter (x), so when we invoke it passing the number 3, it gets assigned to x.

Now go ahead and try implementing the multiply_by_two function by yourself.

Test Cases

test five times two - Run Test

def test_five_times_two():
    assert multiply_by_two(5) == 10

test two times two - Run Test

def test_two_times_two():
    assert multiply_by_two(2) == 4

Solution 1

def multiply_by_two(x):
    return x * 2
def multiply_by_two(x): pass # --- Testing --- # Use the code below for your own testing # by clicking the "Run Code" button. # After you're done, remove the lines below and "Submit Solution". two_times_two = multiply_by_two(2) three_times_two = multiply_by_two(3) five_times_two = multiply_by_two(5) print("2x2 = {}".format(two_times_two)) print("3x2 = {}".format(three_times_two)) print("5x2 = {}".format(five_times_two)) # --- Testing ---