Skip to main content
Practice

coding-quiz-3

---
id: coding-quiz-3
title: Coding Quiz - Create a List of Powers of 2
description: Write a function to generate a list of numbers that are powers of 2
tags:
- Coding Quiz
- List
- Python
sidebar_position: 8
isPublic: false
---

# Coding Quiz - Create a List of Powers of 2

In this coding quiz, you will write a function that generates a list of numbers, each a power of 2.

You will receive an integer **n** from the user and return a list containing values from `2^0` to `2^n`.

For example, if the input integer is `3`, the returned list should be `[1, 2, 4, 8]`.

<br />

```python title="Code Solution"
def solution(n):
# Write your code here
return



Constraints

  • The input integer n must be 0 or greater.

  • You can assume the result of 2^n does not exceed the integer range.




Input and Output Examples

  • Input: 3

  • Output: [1, 2, 4, 8]


  • Input: 5

  • Output: [1, 2, 4, 8, 16, 32]

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.