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
Flujograma de nómina ​
balu736 [363]
Explanation there is the rest in comments

7 0
3 years ago
Give examples of an outdated memory or storage device. what do you think is the main reason they are outdated?
omeli [17]

Answer:

floppy discs:

easily damaged, large compared to newer external storage drives, newer computers don't have a floppy disc drive

Explanation:

8 0
2 years ago
Read 2 more answers
HELP ME ASAP
Ede4ka [16]

Answer:

1 replies 2 tracking

Explanation:

edge

4 0
3 years ago
Read 2 more answers
Help please if you know answer like these I’ll provide my discord.
Natasha_Volkova [10]

ins can insert a time and date.

5 0
3 years ago
How can you minimize a bad background? In other words, how can you make less of a bad background show up in the photo?
Aneli [31]
What you want to do is create a shallow depth of field, this is to make your background blur and focus more on the subject. Set a large aperture, which is a low f-number, around f/1.8 or f/2 and then take a few test shots to see if this is what you would like. If you want everything to be focused in frame just do the opposite.
6 0
3 years ago
Other questions:
  • In a pinhole camera, the image seen in the camera will be inverted<br><br> true<br> false
    13·2 answers
  • 6. Write a program that can multiply an n x m matrix and m x n matrix together: The input specifications are these: Read n and m
    11·1 answer
  • Which statement is correct? (Note: Our selectionsort picks largest items first.) A. The algorithm might be either selectionsort
    9·1 answer
  • What types of issues can you most likely resolve by knowing how to access and use the control panel choose all that apply?
    10·1 answer
  • A user calls you and says that when they try to connect to the internal website, they are prompted for authentication. The user
    14·1 answer
  • David is working in a database that organizes student exam grade information. He needs to find all students who have scored 100
    15·1 answer
  • Write two methods: encrypt and decrypt. encrypt should #take as input a string, and return an encrypted version #of it according
    6·1 answer
  • which of the following uses technical and artistic skills to create visual products that communicate information to an audience?
    14·1 answer
  • How do I get rid of the thing on top? It is driving me INSANE!!
    7·1 answer
  • What is the value of the variable answer after the following code is executed?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!