Power Ladder

Powers of two appear often in programming: memory sizes, bit masks, and binary numbers all use them. Write a function powers_of_two that takes a number n and returns a list of powers of two from 2^0 through 2^n, inclusive. The first element is always 1, because 2^0 equals 1.

Примеры

Ввод
0
Вывод
[1]
Ввод
1
Вывод
[1, 2]
Ввод
4
Вывод
[1, 2, 4, 8, 16]

Нужно реализовать

def powers_of_two(n: int) -> list[int]:

Теги

mathlistsarray
PostgreSQLv16

Тук ще се появи резултатът от изпълнението на кода

Visible tests
1
Input
0
Expected[1]
2
Input
1
Expected[1,2]
3
Input
4
Expected[1,2,4,8,16]
4
Input
2
Expected[1,2,4]
5
Input
5
Expected[1,2,4,8,16,32]
6
Input
7
Expected[1,2,4,8,16,32,64,128]
Focus radio
Paused · SomaFM · Fluid