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
11. What are the two DFS models?12.When you move a file from the Spreadsheets folder to the Corp Documents folder on a Windows S
Vesnalui [34]

Answer/Explanation:

11. Standalone and Domain-based models

12. The moved file takes with it the permission it had in the Spreadsheets folder.

Cheers.

7 0
3 years ago
Roark has just joined a company and in his role as a lead analyst, he will be responsible for determining which systems developm
hram777 [196]

Answer:

Agile/adaptive methods.

Explanation:

The user has just decided to join a firm and will also be accountable to determine whether that system development technique that group uses to establish the latest software for a significant medical distributor to his position as just a lead analyst.

After that, he consumes a week for the purpose to understand his group members for reason to know their strengths and weakness and how would they work under pressure.

So, the following method is required for him to understand about the disadvantages of each of them.

4 0
3 years ago
HURRRYYYY PLZZ!!
vivado [14]

Answer: A. How much is this vehicle's resale value?

6 0
3 years ago
Read 2 more answers
If a touch screen chrome is not charging what is wrong with it
AysviL [449]
Look it up on a best buy website ion know
5 0
3 years ago
Read 2 more answers
Activities provided for the satisfaction of others and consumed at the time of purchase<br> are…
Natasha2012 [34]
The answer is services
6 0
3 years ago
Other questions:
  • Why do we need the Domain Name System (DNS)? Given the domain name www.flamingflamingos.eu, what is the top level domain in this
    5·1 answer
  • Does clearing your hard drive make your computer faster reddit
    13·1 answer
  • You can use ???? a to test tread wear on your tires
    14·2 answers
  • Celeste is writing a paper. However, two pages in, her computer shuts down unexpectedly. She never saved her paper, and all her
    12·2 answers
  • The data-linking feature that allows Internet users to skip directly from a highlighted word to a related file in another comput
    12·2 answers
  • How can you tell the value of a purchase?
    7·1 answer
  • You make an online purchase of a hooded sweatshirt with the logo of the Dallas Cowboys. The next time you log on, your screen ha
    9·1 answer
  • Pls help me!!!!!!!!!!!!!!!!!!!
    11·2 answers
  • Write a function:
    13·1 answer
  • How do cyber criminals target user’s end devices?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!