grokking-algorithms/chapter4/ex4.1.py

14 lines
264 B
Python
Raw Normal View History

2024-01-07 21:19:42 +00:00
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))