Sum of a sequence

* *
链接 Sum of a sequence
难度 7kyu
状态 TODO
日期 --

题意

题解1

def sequence_sum(begin_number, end_number, step):
    #your code here
    if begin_number > end_number:
        return 0
    sum = 0
    num = begin_number
    while num <= end_number:
        sum += num
        num += step
    return sum
def sequence_sum(begin_number, end_number, step):
    #your code here
    if begin_number > end_number:
        return 0
    sum = 0
    num = begin_number
    while num <= end_number:
        sum += num
        num += step
    return sum

题解2

利用python的range结构

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

你可能感兴趣的:(Sum of a sequence)