Your task is to make function, which returns the sum of a sequence of integers.

The sequence is defined by 3 non-negative values: **begin**, **end**, **step**.

If **begin** value is greater than the **end**, function should returns **0**

*Examples*

~~~if-not:nasm

~~~

This is the first kata in the series:

1) Sum of a sequence (this kata)  
2) [Sum of a Sequence [Hard-Core Version]](https://www.codewars.com/kata/sum-of-a-sequence-hard-core-version/javascript)

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def sequence_sum(begin_number, end_number, step):
	

Solutions:
def sequence_sum(start, end, step):
	return sum(range(start, end + 1, step))


def sequence_sum(begin_number, end_number, step):
	return sum(range(begin_number, end_number + 1, step))


def sequence_sum(b, e, s):
	k = (e - b) // s
	return (1 + k) * (b + s * k / 2) if b <= e else 0


def sequence_sum(begin, end, step):
	if begin > end:
		return 0
	else:
		return begin + sequence_sum(begin + step, end, step)


sequence_sum = lambda a, b, c: sum(range(a, b + 1, c))


def sequence_sum(start, stop, step):
	return sum(range(start, stop + 1, step))

def range_sum(n):
	return n * (n + 1) / 2

def multiples_sum(divisor, n):
	return range_sum(n // divisor) * divisor

def sequence_sum(start, stop, step):
	diff = stop - start
	return 0 if start > stop else start * (diff // step + 1) + multiples_sum(step, diff)

def sequence_sum(start, stop, step):
	strides = (stop - start) // step
	return 0 if start > stop else (strides + 1) * (step * strides / 2 + start)


def sequence_sum(begin_number, end_number, step):
	if begin_number > end_number:
		return 0
	if begin_number == end_number:
		return end_number
	else:
		return begin_number + sequence_sum(begin_number + step, end_number, step)


sequence_sum = lambda b, e, s: sum(range(b, e + 1, s))


def sequence_sum(start, stop, step):
	return sum(range(start, stop + 1, step))


def sequence_sum(begin_number, end_number, step):
	output = 0
	for x in range(begin_number, end_number + 1, step):
		output = output + x
	return output


def sequence_sum(begin_number, end_number, step):
	res = 0
	cal_number = begin_number
	while cal_number <= end_number:
		res += cal_number
		cal_number += step
	return res


def sequence_sum(begin_number, end_number, step):
	if begin_number > end_number:
		return 0
	n = (end_number - begin_number) // step
	return begin_number * (n + 1) + step * n * (n + 1) // 2


def sequence_sum(start, stop, step):
	strides = (stop - start) // step
	return 0 if start > stop else (strides + 1) * (step * strides / 2 + start)


def sequence_sum(beg, end, step):
	if beg > end:
		return 0
	return beg + sequence_sum(beg + step, end, step)


def sequence_sum(begin_number, end_number, step):
	if end_number >= begin_number:
		return sum(range(begin_number, end_number + 1, step))
	else:
		return 0


def sequence_sum(begin, end, step):
	return sum(range(begin, end + 1, step))


def sequence_sum(begin_number, end_number, step):
	start = int(begin_number)
	end = int(end_number)
	step = int(step)
	tot = 0
	num = start
	while num <= end:
		tot = tot + num
		num = num + step
	return tot


def sequence_sum(begin_number, end_number, step):
	a = begin_number
	sum = 0
	while a <= end_number:
		sum = sum + a
		a = a + step
	return sum


def sequence_sum(begin_number, end_number, step):
	out = 0
	while begin_number <= end_number:
		out += begin_number
		begin_number += step
	return out


def sequence_sum(a, b, c):
	r = []
	while a <= b:
		r.append(a)
		a += c
	return sum(r)


sequence_sum = lambda s, e, t: sum(range(s, e + 1, t))


def sequence_sum(begin_number, end_number, step):
	if begin_number > end_number:
		return 0
	n = int((end_number - begin_number) / step)
	end_number = begin_number + step * n
	return int((begin_number + end_number) * (n + 1) * 0.5)


def sequence_sum(begin, end, step):
	s = 0
	for i in range(begin, end + 1, step):
		s = s + i
	return s


def sequence_sum(begin_number, end_number, step):
	if begin_number > end_number:
		return 0
	else:
		num = begin_number
		s = begin_number
		for x in range(begin_number, end_number, step):
			if x > end_number - step:
				break
			else:
				num = num + step
				s = s + num
		return s


sequence_sum = lambda b, e, s: (lambda a: a * (a + 1) / 2 * s + b * (a + 1))(int((e - b) / s)) if b <= e else 0


def sequence_sum(begin_number, end_number, step):
	sq = []
	for i in range(begin_number, end_number + 1, step):
		sq.append(i)
	return sum(sq)


def sequence_sum(begin_number, end_number, step):
	liste = []
	while begin_number <= end_number:
		liste.append(begin_number)
		begin_number = begin_number + step
	return sum(liste)


def sequence_sum(begin_number, end_number, step):
	x = begin_number
	st = begin_number + step
	if begin_number > end_number:
		return 0
	else:
		while st <= end_number:
			x += st
			st += step
		return x


def sequence_sum(begin_number, end_number, step):
	sum = 0
	arr = list(range(end_number + 1))
	for i in arr[begin_number:end_number + 1:step]:
		sum += i
	return sum


def sequence_sum(begin, end, step):
	if begin > end:
		return 0
	sum = 0
	for x in range(begin, end + step, step):
		if x > end:
			break
		sum += x
	return sum


def sequence_sum(begin_number, end_number, step):
	num_list = []
	current_num = begin_number
	if begin_number > end_number:
		return 0
	elif begin_number == end_number:
		return begin_number
	else:
		while current_num <= end_number:
			num_list.append(current_num)
			current_num += step
	return sum(num_list)


def sequence_sum(begin_number, end_number, step):
	array = list(range(begin_number, end_number + 1, step))
	return sum(array)


def sequence_sum(begin_number, end_number, step):
	res = begin_number
	var = begin_number + step
	if end_number < begin_number:
		return 0
	else:
		while var <= end_number:
			res += var
			var += step
		return res


def sequence_sum(begin_number, end_number, step):
	if begin_number == end_number:
		return begin_number
	if begin_number > end_number:
		return 0
	sum = 0
	for x in range(begin_number, end_number + 1, step):
		sum += x
	return sum


def sequence_sum(begin_number, end_number, step):
	if begin_number > end_number:
		return 0
	else:
		return begin_number + sequence_sum(begin_number + step, end_number, step)
sequence_sum(7, 8, 9)


def sequence_sum(b, e, s):
	c = 0
	for i in range(b, e + 1, s):
		c += i
	return c


def sequence_sum(begin_number, end_number, step):
	sum_total = 0
	for num in range(begin_number, end_number + 1, step):
		sum_total += num
	return sum_total


def sequence_sum(b, e, s):
	sum = 0
	for i in range(b, e + 1, s):
		sum += i
	return sum
print(sequence_sum(2, 6, 2))


def sequence_sum(b, e, s):
	sum = 0
	while b <= e:
		sum += b
		b += s
	return sum


def sequence_sum(begin, end, step):
	return sum((_ for _ in range(begin, end + 1, step))) if end >= begin else 0


def sequence_sum(begin_number, end_number, step):
	number = 0
	while not begin_number > end_number:
		number += begin_number
		begin_number += step
	return number


def sequence_sum(start, end, step):
	total = 0
	if end < start:
		return 0
	for x in range(start, end + 1, step):
		total += x
	return total


def sequence_sum(b, e, s):
	sums = [i for i in range(b, e + 1, s)]
	return sum(sums)


def sequence_sum(begin_number, end_number, step):
	total = 0
	if begin_number > end_number:
		return 0
	else:
		for number in range(begin_number, end_number + 1, step):
			total += number
	return total


def sequence_sum(begin_number, end_number, step):
	out = 0
	for i in range(begin_number, end_number + 1, step):
		out += i
	return out


def sequence_sum(bn, end, step):
	if bn > end:
		return 0
	else:
		return bn + sequence_sum(bn + step, end, step)


def sequence_sum(bn, end, step):
	print(bn, end, step)
	sum = 0
	if bn > end:
		return 0
	for i in range(bn, end + 1, step):
		sum += i
	return sum


def sequence_sum(begin_number, end_number, step):
	if begin_number > end_number:
		return 0
	else:
		sum = begin_number
		gap = begin_number + step
		while gap <= end_number:
			sum += gap
			gap += step
			print(gap)
		print('sum', sum)
		return sum


def sequence_sum(begin_number, end_number, step):
	kata = 0
	for i in range(begin_number, end_number + 1, step):
		kata += i
	if begin_number > end_number:
		kata = 0
	print(kata)
	return kata
x = 2
y = 6
z = 2
sequence_sum(x, y, z)


def sequence_sum(begin, end, step):
	x = begin
	sum = 0
	while x <= end:
		sum = sum + x
		x = x + step
	return sum


def sequence_sum(begin, end, step):
	arr = []
	if begin > end:
		return 0
	while begin <= end:
		arr.append(begin)
		begin = begin + step
	return sum(arr)


def sequence_sum(i, j, k):
	return sum(list(range(i, j + 1, k)))


def sequence_sum(begin_number, end_number, step):
	s = 0
	for k in range(begin_number, end_number + 1, step):
		s += k
	return s


def sequence_sum(begin_number, end_number, step):
	sum = 0
	if begin_number == end_number:
		sum += end_number
	for i in range(begin_number, end_number, step):
		sum += i
		if i + step == end_number:
			sum += end_number
	return sum


def sequence_sum(begin_number, end_number, step):
	result = 0
	num = begin_number
	while num <= end_number:
		result += num
		num += step
	return result


def sequence_sum(begin_number, end_number, step):
	return sum([n for n in range(begin_number, end_number + 1, step)]) if begin_number <= end_number else 0


def sequence_sum(begin_number, end_number, step):
	num = 0
	if begin_number > end_number:
		return 0
	else:
		for j in range(begin_number, end_number + 1, step):
			num += j
		return num


def sequence_sum(begin_number, end_number, step):
	if begin_number > end_number:
		return 0
	ans = 0.0
	for i in range(begin_number, end_number + 1, step):
		print(i)
		ans += i
	return ans
sequence_sum(7, 6, 2)


def sequence_sum(begin_number, end_number, step):
	return_sum = 0
	stepper = begin_number
	while stepper <= end_number:
		return_sum += stepper
		stepper += step
	return return_sum


def sequence_sum(a, b, d):
	if a <= b:
		return sum(range(a, b + 1, d))
	else:
		return 0


def sequence_sum(begin, end, step):
	d = []
	for i in range(begin, end + 1, step):
		d.append(i)
	return sum(d)


def sequence_sum(begin_number, end_number, step):
	return sum([el for el in range(begin_number, end_number + 1, step)])


def sequence_sum(begin_number, end_number, step):
	steps = (end_number - begin_number) // step + 1
	return steps * begin_number + step * steps * (steps - 1) / 2 if steps > 0 else 0


def sequence_sum(begin_number, end_number, step):
	sum = 0
	if begin_number <= end_number:
		while begin_number <= end_number:
			sum += begin_number
			begin_number += step
		if begin_number < end_number:
			sum += begin_number
		return sum
	elif step >= begin_number - end_number or begin_number > end_number:
		return 0


def sequence_sum(begin_number, end_number, step):
	ssum = 0
	if begin_number <= end_number:
		for i in range(begin_number, end_number + 1, step):
			ssum += i
		return ssum
	else:
		return 0


def sequence_sum(begin_number, end_number, step):
	x = []

	def lala(b, e, s):
		if b <= e:
			x.append(b)
			return lala(b + s, e, s)
		return x
	l = lala(begin_number, end_number, step)
	print(l)
	return sum(l)


def sequence_sum(begin_number, end_number, step):
	if begin_number > end_number:
		return 0
	if begin_number == end_number:
		return begin_number
	sum = begin_number
	curr = begin_number + step
	while curr <= end_number:
		sum += curr
		curr = curr + step
	return sum


def sequence_sum(begin_number, end_number, step):
	if begin_number <= end_number:
		num = begin_number
		fin = begin_number
		while num <= end_number:
			num += step
			fin += num
		if fin > end_number:
			fin -= num
		return fin
	else:
		return 0


def sequence_sum(begin_number, end_number, step):
	x = list(range(begin_number, end_number + 1))
	return sum(x[::step])


def sequence_sum(begin_number, end_number, step):
	return sum((item for item in range(begin_number, end_number + 1, step)))


def sequence_sum(begin_number, end_number, step):
	if begin_number > end_number:
		end = end_number - 1
	else:
		end = end_number + 1
	return sum(range(begin_number, end, step))


def sequence_sum(begin_number, end_number, step):
	ans = [i * step + begin_number for i in range((end_number - begin_number) // step + 1)]
	return sum(ans)


def sequence_sum(begin_number, end_number, step):
	print(begin_number, end_number, step)
	return sum([i for i in range(begin_number, end_number + 1, step)]) if end_number >= begin_number else 0


def sequence_sum(begin_number, end_number, step):
	x = range(begin_number, end_number + 1, step)
	y = sum(x)
	return y


def sequence_sum(begin_number, end_number, step):
	total = 0
	for a in range(begin_number, end_number + 1, step):
		print(a)
		total = total + a
	return total


def sequence_sum(begin_number, end_number, step):
	if begin_number > end_number:
		number = 0
	else:
		number = begin_number
	while begin_number + step <= end_number:
		begin_number += step
		number += begin_number
	return number


def sequence_sum(begin_number, end_number, step):
	if end_number < begin_number:
		return 0
	i = 0
	for z in range(begin_number, end_number + 1, step):
		i += z
	return i


def sequence_sum(begin_number, end_number, step):
	x = []
	count = begin_number
	if begin_number > end_number:
		return 0
	while count <= end_number:
		x.append(count)
		count += step
	return sum(x)