Introducing Python for Algorithm Programming
79
You have a new function,
DoSum()
. This function requires that you provide two
arguments to use it. At least, that’s what you’ve heard so far. Type DoSum() and
press Enter. You see an error message like this one:
TypeError
Traceback (most recent call last)
in ()
----> 1 DoSum()
TypeError: DoSum() missing 2 required positional
arguments: 'Value1' and 'Value2'
Trying
DoSum()
with just one argument would result in another error message. To
use
DoSum()
,you must provide two arguments. To see how this works, type
DoSum(1, 2) and press Enter. You see the expected result of
3
.
Notice that
DoSum()
provides an output value of
3
when you supply
1
and
2
as
inputs. The
return
statement provides the output value. Whenever you see
return
in a function, you know that the function provides an output value.
Do'stlaringiz bilan baham: |