码迷,mamicode.com
首页 > 其他好文 > 详细

【Kata Daily 191010】Grasshopper - Summation(加总)

时间:2019-10-10 22:14:24      阅读:80      评论:0      收藏:0      [点我收藏+]

标签:for   example   write   sum   ever   ati   rom   positive   opp   

题目:

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 191010】Grasshopper - Summation(加总)

标签:for   example   write   sum   ever   ati   rom   positive   opp   

原文地址:https://www.cnblogs.com/bcaixl/p/11650843.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!