Основной код калькулятора

parent 714de535
"""this program calculates operations based on the user input"""
def calculate(val1, val2, operation):
"""
main calculating function
expects first variable, second variable, and operation in order
supports only +,-,*,/
"""
# checking the operation type
match operation:
case '+':
return val1 + val2
case '-':
return val1 - val2
case '*':
return val1 * val2
case '/':
return val1 / val2
case _:
# if user inputs unsuuported operation throw an error
return 'Invalid Operation'
# tests
def test_calculate_summation(val1, val2):
assert calculate(val1, val2, '+') == val1 + val2, 'addition'
def test_calculate_subscription(val1, val2):
assert calculate(val1, val2, '-') == val1 - val2, 'subtraction'
def test_calculate_multiplication(val1, val2):
assert calculate(val1, val2, '*') == val1 * val2, 'multiplication'
def test_calculate_division(val1, val2):
assert calculate(val1, val2, '/') == val1 / val2, 'division'
# thirst variable
a = int(input())
# second variable
b = int(input())
# testing
test_calculate_summation(a,b)
test_calculate_subscription(a,b)
test_calculate_multiplication(a,b)
test_calculate_division(a,b)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment