def calculator(num1,num2, operation): return { "m": num1 * num2, "a": num1 + num2, "s": num1 - num2, "d": num1 / num2, }[operation.lower()]
def calculator(num1,num2, charOperation):answer = 0if operation in ["m","M"]:answer = num1*num2elif operation in ["a","A"]:answer = num1 + num2elif operation in ["s", "S"]:answer = num1 - num2elif operation in ["d","D"]:answer = num1 / num2return answer- def calculator(num1,num2, operation):
- return {
- "m": num1 * num2,
- "a": num1 + num2,
- "s": num1 - num2,
- "d": num1 / num2,
- }[operation.lower()]
import codewars_test as test import solution # or from solution import example @test.describe("Test calculator") def test_group(): @test.it("test addition") def test_case(): test.assert_equals(calculator(1, 1, "a"), 2) @test.it("test subtraction") def test_case(): test.assert_equals(calculator(1, 1, "s"), 0) @test.it("test multiplication") def test_case(): test.assert_equals(calculator(2, 2, "m"), 4) @test.it("test division") def test_case(): test.assert_equals(calculator(6, 2, "d"), 3)
- import codewars_test as test
- import solution # or from solution import example
- @test.describe("Test calculator")
- def test_group():
- @test.it("test addition")
- def test_case():
- test.assert_equals(calculator(1, 1, "a"), 2)
- @test.it("test subtraction")
- def test_case():
- test.assert_equals(calculator(1, 1, "s"), 0)
- @test.it("test multiplication")
- def test_case():
- test.assert_equals(calculator(2, 2, "m"), 4)
- @test.it("test division")
- def test_case():
- test.assert_equals(calculator(6, 2, "d"), 3)