Python 3.13.5 (v3.13.5:6cb20a219a8, Jun 11 2025, 12:23:45) [Clang 16.0.0 (clang-1600.0.26.6)]
Type "help", "copyright", "credits" or "license" for more information.
def add_one(price: int) -> int: """Return a number one more than price.
>>> add_one(3)
4
>>> add_one(-2)
-1
"""
return price + 1
add_one(3)
4
add_one(-2)
-1/Users/teaching/courses/108/lectures/w02/9am/tue/shell-sep9-0501.txt
result = add_one(-2)
result
-1
# Terminology
# function name: add_one
# function parameter: price/Users/teaching/courses/108/lectures/w02/9am/tue/shell-sep9-0501.txt
# - the parameter gets its value when the function is called
# - a new value is computed in the function body
# - the memory address of the object that contains the computed value is returned by the function
# - a variable can be assigned to refer to that value
#
# 3 and -1 are examples of arguments to the function # arguments give a value to the parameter variable before the function body is executed
[evaluate function_definitions.py]
double(7.0)
14.0
double(5.7)
11.4
[evaluate function_definitions.py]
our_maximum(1.5, 2.5)
2.5
our_maximum(4.0, 3.7)
4.0
[evaluate function_definitions.py]
max_of_min(4.0, 3.7, 6.0, 3.5)
3.7
max_of_min(1.0, 1.7, 4.5, 3.0)
3.0
# Need exactly 4 arguments, otherwise an error occurs.
max_of_min(1.0, 1.7, 4.5)
Traceback (most recent call last):
Python Shell, prompt 10, line 1
builtins.TypeError: max_of_min() missing 1 required positional argument: 'value2'
# We have not run the code yet, so cannot call the function from the Python shell.
get_distance(3.0, 4.0)
Traceback (most recent call last):
Python Shell, prompt 11, line 1
builtins.NameError: name 'get_distance' is not defined
[evaluate distance.py]
get_distance(3.0, 4.0)
5.0
get_distance(0.0, 0.0)
0.0
'Marcia ' * 3
'Marcia Marcia Marcia '
'hello' * 0
''
[evaluate fdr.py]
repeat_word('Marcia ', 3)
'Marcia Marcia Marcia '
repeat_word('hello', 0)
''
calculate_tax(2.00, 0.13)
0.26
calculate_tax(30.00, 0.05)
1.5