add summation

This commit is contained in:
onyx-and-iris 2024-01-07 21:19:42 +00:00
parent 3a138acf93
commit 22545b8911

13
chapter4/summation.py Normal file
View File

@ -0,0 +1,13 @@
class Number:
def __init__(self, value):
self.value = value
def summation(nums):
if len(nums) == 1:
return nums[0].value
return nums[0].value + summation(nums[1:])
nums = [Number(i) for i in range(0, 100, 3)]
print(summation(nums))