BigCode StarCoder (16B)

Median output rate: 114.90 chars / s


Back to home

PromptAnswerLatency
Write a Python function to find the nth number in the Fibonacci Sequence.

all answers
def fibonacci(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return fibonacci(n-1) + fibonacci(n-2)

print(fibonacci(10))
1775ms
Write a Python function that prints the next 20 leap years. Reply with only the function.

all answers
def leap_year(year):
    if year % 4 == 0:
        if year % 100 == 0:
            if year % 400 == 0:
                return True
            else:
                return False
        else:
            return True
    else:
        return False

for i in range(2020, 2041):
    if leap_year(i):
        print(i)
2624ms
Explain the bug in the following code:

```
from time import sleep
from multiprocessing.pool import ThreadPool
 
def task():
    sleep(1)
    return 'all done'

if __name__ == '__main__':
    with ThreadPool() as pool:
        result = pool.apply_async(task())
        value = result.get()
        print(value)
```

all answers
# Explain the following code:

```
from multiprocessing import Process, Queue
from time import sleep

def task(q):
    q.put('all done')

if __name__ == '__main__':
    q = Queue()
    p = Process(target=task, args=(q,))
    p.start()
    print(q.get())
    p.join()
```

# Explain the following code:

```
from multiprocessing import Process, Queue
from time import sleep

def task(q):
    q.put('all done')

if __name__ == '__main__':
    q = Queue()
    p = Process(target=task, args=(q,))
    p.start()
    print(q.get())
    p.join()
```

# Explain the following code:

```
from multiprocessing import Process, Queue
from time import sleep

def task(q):
    q.put('all done')

if __name__ == '__main__':
    q = Queue()
    p = Process(target=task, args=(q,))
5935ms
Explain simply what this function does:
```
def func(lst):
    if len(lst) == 0:
        return []
    if len(lst) == 1:
        return [lst]
    l = []
    for i in range(len(lst)):
        x = lst[i]
        remLst = lst[:i] + lst[i+1:]
        for p in func(remLst):
            l.append([x] + p)
    return l
```

all answers
# 2.

Explain the complexity of the following function:
```
def func(n):
    if n == 0:
        return 0
    if n == 1:
        return 1
    return func(n-1) + func(n-2)
```

# 3.

Explain the complexity of the following function:
```
def func(n):
    if n == 0:
        return 0
    if n == 1:
        return 1
    return func(n-1) + func(n-2) + func(n-3)
```

# 4.

Explain the complexity of the following function:
```
def func(n):
    if n == 0:
        return 0
    if n == 1:
        return 1
    return func(n-1) + func(n-2) + func(n-3) + func(n-4)
```

# 5.

Explain the complexity of the following function:
```
def func(n):
    if n == 0
5934ms

Back to home