tags:
- code
topic: Sum
difficulty: Easy
link:
date: 2023-10-28
Problem
Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0.
summation(2) # returns 3
summation(8) # returns 36
def summation(num):
return sum([i for i in range(1, num+1)])
def summation(num):
return sum(xrange(num + 1))
def summation(num):
return sum(range(1,num+1))
xrange
is a Python2 relic and has been removed.