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
Discuss what repetitions structures are, and how they differ from the vectorization approaches we have previously studied in the
gogolik [260]

Repetition structures, or loops, are used when a program needs to repeatedly process one or more instructions until some condition is met, at which time the loop ends. Many programming tasks are repetitive, having little variation from one item to the next. Vectorized mathematical code appears more like the mathematical expressions found in textbooks, making the code easier to understand. That is the difference. Hope I could help you on Brainly.com!

6 0
3 years ago
Keyboards and printers are two examples of _________ devices.
galben [10]
Input device your welcome
8 0
3 years ago
HELPPPP KOKICHI IS OUT TO KILL ME
Ne4ueva [31]
Oh my- good luck with that-
3 0
2 years ago
___________ is an unsecured client server application / protocol that transfers files between two computers.
Alexus [3.1K]
It is known as the File Transfer Protocol or FTP. It is based on a customer server demonstrate design and uses isolate control and information associations between the customer and the server. FTP clients may conform themselves with an unmistakable content sign-in convention, regularly as a username and secret word, yet can interface namelessly if the server is designed to permit it.
6 0
3 years ago
Which of the following is true about advertisements?
katrin [286]

the answer is they often contain biases :)

3 0
2 years ago
Other questions:
  • Tower defense is included under which genre of game
    15·2 answers
  • A ________ is a collection of forms, reports, queries, and programs that serves as an intermediary between users and database da
    6·1 answer
  • The World Wide Web (WWW) is a network of links on the Internet to documents containing text, graphics, video, and sound, but doe
    10·1 answer
  • _____ is used to temporarily hold small units of program instructions and data immediately before, during, and after execution b
    10·1 answer
  • You are the administrator of the Sybex website. You are working when suddenly web server and network utilization spikes to 100 p
    15·1 answer
  • 4
    12·2 answers
  • Sigma Technology is a company based in Singapore, with branches in 24 countries. It needs multiple CAs in different locations to
    6·1 answer
  • Suppose that you have declared a numeric array named numbers, and two of its elements are numbers[1] and numbers[4]. You know th
    10·1 answer
  • balance exercises used for introducing balance training should initially involve little joint motion and improve what type of co
    9·1 answer
  • 5 points)*list all of the data that needs to be kept track of for the scenario above in a 1nf (flat file) table (20 points)*use
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!