def run(Type ,*args): if Type == 'add': a = 0 for i in args: a+=i return a elif Type == 'minum': a = 0 for i in args: if a == 0: a+=i else: a-=i return a elif Type == 'multiply': a = 1 for i in args: a =a*i return a elif Type == 'divide': a = args[0] for i in args: if i == a: pass else: a = a//i return a
add = lambda *args:sum(args)def minum(*args):xxx = args[0]for i in range(1,len(args)):xxx = xxx - args[i]return xxxdef multiply(*args):xxx = 1for i in args:xxx = xxx * ireturn xxxdef divide(*args):xxx = args[0]for i in args[1:]:xxx = xxx / ireturn xxxdef run(func,*args):return func(*args)- def run(Type ,*args):
- if Type == 'add':
- a = 0
- for i in args: a+=i
- return a
- elif Type == 'minum':
- a = 0
- for i in args:
- if a == 0:
- a+=i
- else:
- a-=i
- return a
- elif Type == 'multiply':
- a = 1
- for i in args: a =a*i
- return a
- elif Type == 'divide':
- a = args[0]
- for i in args:
- if i == a: pass
- else: a = a//i
- return a
import codewars_test as test # TODO Write tests import solution # or from solution import example # test.assert_equals(actual, expected, [optional] message) @test.describe("Example") def test_group(): @test.it("test case") def test_case(): test.assert_equals(run('add',100,100,1000,500,300),2000) test.assert_equals(run('minum',1000,100),900) test.assert_equals(run('multiply',12,2),24) test.assert_equals(run('divide',100,25),4)
- import codewars_test as test
- # TODO Write tests
- import solution # or from solution import example
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(run(add,100,100,1000,500,300),2000)test.assert_equals(run(minum,1000,100),900)test.assert_equals(run(multiply,12,2),24)test.assert_equals(run(divide,100,25),4)- test.assert_equals(run('add',100,100,1000,500,300),2000)
- test.assert_equals(run('minum',1000,100),900)
- test.assert_equals(run('multiply',12,2),24)
- test.assert_equals(run('divide',100,25),4)