Kata Daily 191010Grasshopper - Summation(加总)
Posted bcaixl
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kata Daily 191010Grasshopper - Summation(加总)相关的知识,希望对你有一定的参考价值。
题目:
Summation
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.
For example:
summation(2) -> 3
1 + 2
summation(8) -> 36
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8
解题方法:
很简单的题目:
def summation(num): return sum([x for x in range(num+1)])
以上是关于Kata Daily 191010Grasshopper - Summation(加总)的主要内容,如果未能解决你的问题,请参考以下文章
Kata Daily 190917Numericals of a String(字符出现的次数)
Kata Daily 191012Find numbers which are divisible by given number