Q1: A Plus Abs B
Python’s operator
module defines binary functions for Python’s intrinsic (固有的) arithmetic operators. For example, calling operator.add(2,3)
is equivalent to calling the expression 2 + 3
; both will return 5
.
Note that when the
operator
module is imported into the namespace, like at the top ofhw01.py
, you can just calladd(2,3)
instead ofoperator.add(2,3)
.
Fill in the blanks in the following function for adding a
to the absolute value of b
, without calling abs
. You may not modify any of the provided code other than the two blanks.
1 | def a_plus_abs_b(a, b): |
Use Ok to test your code:
1 | python3 ok -q a_plus_abs_b✂️ |
Use Ok to run the local syntax checker (which checks that you didn’t modify any of the provided code other than the two blanks):
1 | python3 ok -q a_plus_abs_b_syntax_check |