python怎么求加到n项和?下面给大家介绍两种方法:
方法1、使用for循环
def accSum(n): sum = 0 for i in range(1, n+1): #[1,n+1) sum += i return sum