Skip to content

Latest commit

 

History

History
54 lines (30 loc) · 994 Bytes

Sum_of_a_sequence.md

File metadata and controls

54 lines (30 loc) · 994 Bytes

CodeWars Python Solutions


Sum of a sequence

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

sequenceSum(2,2,2) === 2
sequenceSum(2,6,2) === 12 // 2 + 4 + 6
sequenceSum(1,5,1) === 15 // 1 + 2 + 3 + 4 + 5
sequenceSum(1,5,3) === 5 // 1 + 4

This is the first kata in the series:

  1. Sum of a sequence (this kata)
  2. Sum of a Sequence [Hard-Core Version]

Given Code

def sequence_sum(begin_number, end_number, step):
    #your code here

Solution

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

See on CodeWars.com