Default values

Very bottom is the correct code. Num is not defined with a default value so how does it produce 10, 20, 30?

I wrote the code to say:
def first_three_multiples(num):
num = 123
return num *3
print(num *1)
print(num *2)
print(num *3)

The above said num wasn’t defined so I changed it to:
def first_three_multiples(num):
return num 3
num = 1
print(num *1)
print(num *2)
print(num *3)

This gave me 6, 12, 18 but no zero’s

Write your first_three_multiples function here

def first_three_multiples(num):


print(num * 2)

print(num * 3)

return num * 3  

Uncomment these function calls to test your first_three_multiples function:


should print 10, 20, 30, and return 30


should print 0, 0, 0, and return 0

Please see How do I format code in my posts? as the forums will remove indentation and such which makes code very difficult to read, especially for an indentation reliant language like Python.

In that example it doesn’t need a default, you pass a value of 10 as the argument for num. The default would only matter if you didn’t pass an argument.

Be aware that you’ll have problems writing statements after return as they’ll never be executed, if return is executed then the currently executing function exits at that point.

So just so I am tracking when I uncommented those calls that became the argument for the function?

Trying to wrap my head around calling the function when the calls aren’t indented because I keep thinking that the indented portion only applies to the function. So I can use any argument outside of the function (not indented) as long as I reference the function which would change the parameter to any argument I desire?

It’s the body of the function that must be indented (code that should run only when the function is called). The actual calls to the function do not have to be indented (unless part of some code that already requires indentation). As for the argument, I think you’ve got the right idea. If you pass an argument of 10 then you basically assign 10 to num inside the function. If it helps the following is perfectly valid syntax-


This would be passing a keyword argument, in this example it’s exactly the same as first_three_multiples(10). You’ll likely learn more about it in due course. The main point being that you can make multiple calls and num (inside the function) is assigned to whatever you pass…

1 Like

Can you give me an example of," unless part of some code that already requires indentation."

I am thinking that means that I can make a call inside the body of the function?

My issue is understanding when I should be in the body of the function and when I should be out of the body.

Indentation is used for a few things in Python, like if statements and for loops. For example the indentation before the call to first_three_multiples is necessary for the syntax of the if statement below-

x = 3
if x > 5:

Another example would be indentation used for the body of classes and functions. Here the first function called double is indented as it is part of the body for another function:

def double(x):
    return x * 2

def double_add_one(x):
    double_x = double(x)
    return double_x + 1