Arithmetic Expression
Consider an arithmetic expression of the form a#b=c
. Check whether it is possible to replace #
with one of the four signs: +
, -
, *
or /
to obtain a correct expression.
Example
For
a = 2
,b = 3
, andc = 5
, the output should bearithmetic_expression(a, b, c) = true
We can replace
#
with a+
to obtain2 + 3 = 5
, so the answer istrue
.For
a = 8
,b = 2
, andc = 4
, the output should bearithmetic_expression(a, b, c) = true
We can replace
#
with a/
to obtain8 / 2 = 4
, so the answer istrue
.For
a = 8
,b = 3
, andc = 2
, the output should bearithmetic_expression(a, b, c) = false
8 + 3 = 11 ≠ 2
;8 - 3 = 5 ≠ 2
;8 * 3 = 24 ≠ 2
;8 / 3 = 2.(6) ≠ 2
.
So the answer is
false
.
Solution
py
def arithmetic_expression(a, b, c):
return (a + b == c) or (a - b == c) or (a * b == c) or (a / b == c)
print(arithmetic_expression(8, 3, 12))