Python 代码:求 1 到 n 的和
def sum_of_n_numbers(n): sum = 0 for i in range(1, n+1): sum += i return sum
n = int(input('Enter the value of n: ')) result = sum_of_n_numbers(n) print('Sum of first', n, 'numbers is', result)
原文地址: https://www.cveoy.top/t/topic/o6ST 著作权归作者所有。请勿转载和采集!