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
Should every presentation have a beggening middle and end​
REY [17]

Answer:

yes every presentation should have a beginning middle & end.

Explanation:

you should include these 5 parts

- introduction

- objective

- overview

- presentation

- summary/conclusion

6 0
2 years ago
Write Java program to allow the user to input the amount of deposit, yearly interest rate (percentage), and income tax(percentag
Vedmedyk [2.9K]

Answer:

import java.util.Scanner;

public class num12 {

   public static void main(String[] args) {

       Scanner scr = new Scanner(System.in);

       System.out.println("Enter a Deposit Amount");

       double amt = scr.nextDouble();

       System.out.println("Income tax in percentage");

       double incomeTaxRate = scr.nextDouble()/100;

       System.out.println("Yearly interest rate:");

       double rate = scr.nextDouble();

       double intRate = rate/100;

       double interest = (amt*intRate)-(amt*incomeTaxRate);

       System.out.println("The Interest on "+amt+" at "+rate+"% after one year is "+interest);

   }

}

Explanation:

Find the sample output attached

Java's Scanner class is used to prompt and receive values for deposit amount, income tax rate and interest rate

The yearly interest is calculate by interest = (amt*intRate)-(amt*incomeTaxRate);

3 0
3 years ago
What are three coding languages that are used to build websites?
dem82 [27]

Answer:

Python, Javascript, and Java

Explanation:

These are the main coding languages used for building most websites.

4 0
2 years ago
Which network device is capable of blocking network connections that identify as potentially malicious
Katarina [22]
Gateway is the correct answer
6 0
3 years ago
Why is the keyboard arranged in the QWERTY style?
ArbitrLikvidat [17]
Most of us were taught that the man who invented the keyboard created the QWERTY design to slow typists down. The faster someone typed, the more often the typewriter jammed
6 0
3 years ago
Read 2 more answers
Other questions:
  • A local area network is: a large central network that connects other networks in a distance spanning exactly 5 miles. a group of
    8·1 answer
  • What is the difference between a key and a superkey?
    10·1 answer
  • 8. How can you prevent your VMs receiving DHCP server messages from unauthorized virtual machine pretending to be DHCP servers?
    6·1 answer
  • Among the eight unique features of​ e-commerce, which is related to the ability to interact with web technology​ everywhere?
    14·1 answer
  • What are the values of a[k] and a[k+1] after code corresponding to the following pseudocode runs?
    9·2 answers
  • How do open online courses help with independent learning
    6·2 answers
  • Shelly recorded an audio composition for her presentation. Arrange the following steps that Shelly followed in the proper order.
    6·1 answer
  • Mecanismo que permite conocer si la persona que esta ingresando a un sistema es realmente quien deba y no un intruso
    13·1 answer
  • Which of the following best describes the impact of Creative Commons?
    7·1 answer
  • Write a function where you are given: a list of numbers "nums", a number to search for "num". Return the index of "num" in the l
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!