Some functions in Python take a long list of arguments, and in most cases, it’s convenient to have default values for those arguments. For example, the default value for the
endparameter of the
\n- a new line. But if someone wants to print another symbol in the end, they can provide it with
end='*', for instance. We can define default arguments in our functions as well:
def work(hours, from_home=True): if from_home: print('Home sweet home...') else: print("Let's meet some people!") return hours - 2 work(8) work(8, True) work(8, False)
In this example, we have to provide the number of hours to the
work()function, but we can skip the
from_homeparameter. If we don’t provide it, it will be set to
Trueas we have defined the function as
def work(hours, from_home=True).
Fill in the function to produce the correct result. The function should compute the distance between two points
. In some cases, the second coordinate is omitted, and therefore, the distance should be computed from the origin of the coordinate system -
The function should accept 4 arguments
and return the distance between those.
As a reminder, the distance between two points can be calculated with:
1 1 1 2