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
Log in om je inzendingsgeschiedenis te zien
InloggenLog in om de AI-mentor te gebruiken
InloggenVisible tests
1
Input
0Expected
[1]2
Input
1Expected
[1,2]3
Input
4Expected
[1,2,4,8,16]4
Input
2Expected
[1,2,4]5
Input
5Expected
[1,2,4,8,16,32]6
Input
7Expected
[1,2,4,8,16,32,64,128]Focus radio
Paused · SomaFM · Fluid