add
add=lambda a,b:a+b
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
import random
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("add")
def add():
for i in range(100):
a = random.randint(1,1000)
b = random.randint(1, 1000)
c = a+b
test.assert_equals(solution.add(a,b),c)
Fundamentals
Mathematics
def m(a, b): # Did you know? This is an implementation of Long Multiplacation negative_result = (a < 0) ^ (b < 0) a, b = abs(a), abs(b) a_str = str(a)[::-1] b_str = str(b)[::-1] result_length = len(a_str) + len(b_str) result = [0] * result_length for i in range(len(a_str)): for j in range(len(b_str)): digit_a = int(a_str[i]) digit_b = int(b_str[j]) product = digit_a * digit_b result[i + j] += product carry = result[i + j] // 10 result[i + j] %= 10 result[i + j + 1] += carry while len(result) > 1 and result[-1] == 0: result.pop() result_str = ''.join(map(str, result[::-1])) final_result = int(result_str) return -final_result if negative_result else final_result # test me pls
m = __import__('operator').mul- def m(a, b):
- # Did you know? This is an implementation of Long Multiplacation
- negative_result = (a < 0) ^ (b < 0)
- a, b = abs(a), abs(b)
- a_str = str(a)[::-1]
- b_str = str(b)[::-1]
- result_length = len(a_str) + len(b_str)
- result = [0] * result_length
- for i in range(len(a_str)):
- for j in range(len(b_str)):
- digit_a = int(a_str[i])
- digit_b = int(b_str[j])
- product = digit_a * digit_b
- result[i + j] += product
- carry = result[i + j] // 10
- result[i + j] %= 10
- result[i + j + 1] += carry
- while len(result) > 1 and result[-1] == 0:
- result.pop()
- result_str = ''.join(map(str, result[::-1]))
- final_result = int(result_str)
- return -final_result if negative_result else final_result
- # test me pls