Mode:
Duration:
Output
Fibonacci: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] Primes up to 30: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] Even squares: [4, 16, 36, 64, 100]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import math
from typing import List, Optional
def fibonacci(n: int) -> List[int]:
"""Generate fibonacci sequence up to n numbers"""
if n <= 0:
return []
elif n == 1:
return [0]
fib = [0, 1]
for i in range(2, n):
fib.append(fib[i-1] + fib[i-2])
return fib
def find_primes(limit: int) -> List[int]:
"""Find all prime numbers up to limit using sieve"""
primes = []
sieve = [True] * (limit + 1)
for i in range(2, int(math.sqrt(limit)) + 1):
if sieve[i]:
for j in range(i * i, limit + 1, i):
sieve[j] = False
return [i for i in range(2, limit + 1) if sieve[i]]
# Main execution
if __name__ == "__main__":
fib_sequence = fibonacci(10)
print(f"Fibonacci: {fib_sequence}")
primes = find_primes(30)
print(f"Primes up to 30: {primes}")
# List comprehension example
squares = [x**2 for x in range(1, 11) if x % 2 == 0]
print(f"Even squares: {squares}")Coding works best on desktop or with an external keyboard.
~`
!1
@2
#3
$4
%5
^6
&7
*8
(9
)0
_-
+=
⌫
Tab
Q
W
E
R
T
Y
U
I
O
P
{[
}]
|\
Caps
A
S
D
F
G
H
J
K
L
:;
"'
↵
⇧
Z
X
C
V
B
N
M
<,
>.
?/
⇧
Ctrl
⊞
Alt
␣
Alt
⊞
Ctx
Ctrl
👉Middle
iL Pinky
L Ring
L Middle
L Index
Thumb
R Index
R Middle
R Ring
R Pinky