logo CodeStepByStep logo

print_powers_of_2

Language/Type: Python math parameters

Write a function named print_powers_of_2 that accepts a maximum number as a parameter and prints each power of 2 from 20 (1) up to that maximum power, inclusive, separated by spaces. For example, the call of print_powers_of_2(10) should produce the following output:

1 2 4 8 16 32 64 128 256 512 1024

You may assume that the value passed is 0 or greater.

Type your Python solution code here:

This is a function exercise. Write a Python function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.