Python Tasks & ML | Задачи по питону и машинному обучению
9.29K subscribers
27 photos
1 file
36 links
Algorithms, functions, classes, regular expressions, iterators, generators, OOP, exceptions, NumPy, pandas, scikit-learn
https://telega.in/c/python_tasks

Questions — @dina_ladnyuk
Download Telegram
Что выведет код?

def digits(n):
if n < 10:
return 1
return 1 + digits(n // 10)

print(digits(1234))
Что выведет код?

def tail_sum(n, acc=0):
if n == 0:
return acc
return tail_sum(n - 1, acc + n)

print(tail_sum(5))
👍1
Что выведет код?

cache = {}

def fib(n):
if n in cache:
return cache[n]
if n <= 1:
cache[n] = n
else:
cache[n] = fib(n - 1) + fib(n - 2)
return cache[n]

print(fib(6))
👍1
Что выведет код?

def count_items(lst):
count = 0
for item in lst:
if isinstance(item, list):
count += count_items(item)
else:
count += 1
return count

print(count_items([1, [2, 3], [4, [5]]]))