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]
2 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]2 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
Gabe wants to move text from one document to another document. He should _____.
Lorico [155]
Copy and paste the text
8 0
3 years ago
Read 2 more answers
What lets you do many things, like write book reports and stories?
Shalnov [3]

Answer:

4. application programs

Explanation:

5 0
3 years ago
In a linked chain implementation of a queue, the performance of the enqueue operation
alexdok [17]

Answer:

A.O(1)

Explanation:

In the implementation of queue by using linked chain the performance of  the enqueue operation is O(1).We have to  maintain  two pointers one  head and the other tailand  for  enqueue operation  we have to insert element  to the next of the tail and then  make that element  tail.Which takes O(1) time.

4 0
2 years ago
Implement a function inValues() that asks the user to input a set of nonzero floating-point values. When the user enters a value
elena-s [515]

Answer:

Explanation:

The following is written in Python and uses exception handling to do exactly as requested. It then goes adding all of the integer values to an array called num_list and finally adding them all together when the function ends.

def in_values():

   num_list = []

   while True:

       try:

           num = input("Input non-zero floating point: ")

           num = int(num)

           if num == 0:

               break

           else:

               num_list.append(num)

       except ValueError:

           print("No valid integer! Please try again ...")

           try:

               num = input("Input non-zero floating point: ")

               num = int(num)

               break

           except ValueError:

               break

   sum = 0

   for number in num_list:

       sum += number

   return sum

5 0
2 years ago
Which is true about SSH and Telnet?
MaRussiya [10]

Answer:

Data is encrypted on SSH

Explanation:

Telnet and SSH both are the networking protocols. These protocol are used for the security of data. In telnet data is sent over the link without any encryption. That is the reason, in telnet protocol data is less secure.

In SSH (Security Shell) protocol data has been encrypted before transmission. The encryption of data make it more secure between transmitter and receiver.

So the true statement is that, SSH has data encryption.

8 0
3 years ago
Other questions:
  • Which of the following commands would I use to begin a new presentation?
    14·1 answer
  • _______ can be used to prevent busy waiting when implementing a semaphore.
    15·1 answer
  • The ________ phase is a technical blueprint for a whole system which captures all aspects of how the system's components will fu
    9·1 answer
  • Ebba received a message from one of her tech support employees. In violation of company policy, a user had downloaded a free pro
    14·1 answer
  • The Windows taskbar is generally found _____. at the top of the screen in the Start menu at the bottom of the screen at the righ
    14·2 answers
  • Help me with this, please. Are vacuum cleaners, Cd players, and telephones considered computers? Do they store any data or proce
    8·2 answers
  • What is the meaning of Re:?
    12·2 answers
  • What is functionality criteria or alternative word
    8·1 answer
  • Write a program that will add up the series of numbers: 99, 98, 97… 3, 2, 1. The program should print the running total as well
    13·1 answer
  • Put these numbers in order from smallest to largest:<br> 1. 00101112<br> 2. 011110<br> 3. 011110112
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!