1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nata [24]
3 years ago
9

Write a recursive function is_pow2(n) that returns True if the positive integer n is an integer power of 2, and False otherwise.

For example: function call return value is_pow2(1) True is_pow2(2) True is_pow2(3) False is_pow2(4) True is_pow2(5) False is_pow2(6) False is_pow2(7) False is_pow2(8) True is_pow2(9) False is_pow2(255) False is_pow2(256) True Hint: Consider using repeated floor division.
Computers and Technology
1 answer:
bezimeni [28]3 years ago
8 0

Answer:

In Python:

def is_power(n):

   if n > 2:

       n = n/2

       return is_power(n)

   elif n == 2:

       return True

   else:

       return False

Explanation:

This defines the function

def is_power(n):

If n is greater than 0

   if n > 2:

Divide n by 2

       n = n/2

Call the function

       return is_power(n)

If n equals 2

   elif n == 2:

Return True

       return True

If n is less than 2

   else:

Then, return false

       return False

You might be interested in
How many micro processors will a small computer have? A. none B. two C. one D. three
kifflom [539]

Answer:

letter C

They only have one chip with two complete microprocessors on it, both of them share one path to memory and peripherals.

3 0
3 years ago
Read 2 more answers
Which block in this module represents the variable?
sasho [114]

Explanation:

jdbfifnmathljnfeijrjdjej.http.com

6 0
3 years ago
A communications objective is:?
creativ13 [48]
D. For example, if your ad is about cigars and it is targeted to 5-year-old girls who just want a doll, then you're not going to get a lot of sales.
5 0
4 years ago
6. You should check your tire pressure
tatyana61 [14]
Answer

Once every week

3 0
3 years ago
Alex is creating a new website to help college freshman succeed during their first year away from home. How can he beat use the
Aleksandr [31]

Answer: I would say do a google search but the most plausible answer is A.

4 0
4 years ago
Read 2 more answers
Other questions:
  • Which of the following is a primary source?
    6·2 answers
  • For C++ (please make sure it runs properly)
    14·1 answer
  • Define what is meant by an entity in a data model. How should an entity be named? What information about an entity should be sto
    5·1 answer
  • A router has just received the following new IP addresses: 88.62.108.0/21, 88.62.116.0/21, 88.62.120.0/21 and 88.62.128.0/21. If
    5·1 answer
  • How can I unblock Brainly?
    12·2 answers
  • Expliquer les règles à respecter quand on fait une recherche sur internet.
    7·1 answer
  • 2. Which Interface uses
    7·1 answer
  • A photographer stores digital photographs on her computer. In this case the photographs are considered the data. Each photograph
    6·1 answer
  • Filtering is a function of _____.
    5·1 answer
  • What is a good indicator that someone on social media is not who he or she claims to be?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!