Ответ:
# Задание 1
class Dog(object):
def eat(self):
print('Eat something')
def drink(self):
print('Drink something')
def say(self):
print('Woof! Woof!')
# Задание 2
class Fibonacci:
def __init__(self, num):
self.num = num
def calculate_num(self):
a = 0
b = 1
if self.num == 0:
return a
elif self.num == 1:
return b
else:
for i in range(2, self.num):
c = a + b
a = b
b = c
return b
def calculate_sum(self):
a = 0
b = 1
array = [0, 1]
if self.num == 0:
return a
elif self.num == 1:
return b
else:
for i in range(2, self.num):
c = a + b
a = b
b = c
array.append(b)
return sum(array)
fibo = Fibonacci(9)
print(fibo.calculate_sum())
Объяснение:
Python 3.8.2