Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
One-liner list comprehension solution in Clear category for Sum of Integers by H0r4c3
def sum_upto_n(N: int) -> int:
return sum([number for number in range(N+1)])
print("Example:")
print(sum_upto_n(11))
# These "asserts" are used for self-checking
assert sum_upto_n(1) == 1
assert sum_upto_n(2) == 3
assert sum_upto_n(3) == 6
assert sum_upto_n(4) == 10
assert sum_upto_n(5) == 15
assert sum_upto_n(10) == 55
assert sum_upto_n(20) == 210
assert sum_upto_n(100) == 5050
assert sum_upto_n(200) == 20100
assert sum_upto_n(500) == 125250
print("The mission is done! Click 'Check Solution' to earn rewards!")
July 14, 2024