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
AfilCa [17]
3 years ago
9

Write the definition of a function named printpoweroftwostars that receives a non-negative integer n and prints a line consistin

g of "2 to the n" asterisks. so, if the function received 4 it would print 2 to the 4 asterisks, that is, 16 asterisks: **************** and if it received 0 it would print 2 to the 0 (i.e. 1) asterisks: * the function must not use a loop of any kind (for, while, do-while) to accomplish its job
Computers and Technology
1 answer:
Aleksandr-060686 [28]3 years ago
4 0
To accomplish this without using a loop,
we can use math on a string.

Example:
print("apple" * 8)

Output:
appleappleappleappleappleappleappleapple

In this example,
the multiplication by 8 actually creates 8 copies of the string.

So that's the type of logic we want to apply to our problem.

<span>def powersOfTwo(number):
if number >= 0:
return print("*" * 2**number)
else:
<span>return

Hmm I can't make indentations in this box,
so it's doesn't format correctly.
Hopefully you get the idea though.

We're taking the string containing an asterisk and copying it 2^(number) times.

Beyond that you will need to call the function below.
Test it with some different values.

powersOfTwo(4) should print 2^4 asterisks: ****************</span></span>
You might be interested in
Question 1 (True/False Worth 3 points)
ANTONII [103]
False because the internet connects with multiple communication networks to exchange information
6 0
2 years ago
Convert to binary140
marshall27 [118]

00110001 00110100 00110000

5 0
3 years ago
Consider the code fragment below (with nested loops). int sum = 0;for (int i = 1; i &lt; 5; i++) for (int j = 1; j &lt;= i; j++)
sammy [17]

Answer:

Option d is the correct answer for the above question.

Explanation:

  • The first loop of the program has a second loop and then the statement. In this scenario, the second loop executes for the value of the first loop and the statement executes for the value of the second loop.
  • The first loop executes 4 times, Then the second loop or inner loop executes n times for the n iteration of the first loop, for example, 1 time for the first iteration of the first loop, 2 times for the second iteration of the first loop and so on.
  • Then the inner loop executes (1+2+3+4) iteration which gives the result 10 iterations.
  • The sum initial value is 0 and the "sum++", increase the value of the sum by 1.
  • So the value of the sum becomes 10 after completing 10 iterations of the inner for loop.
  • Hence the 10 will be the output. So the Option d is the correct answer while the other is not.
3 0
3 years ago
Combination of two or more networks
bezimeni [28]
The combination of two or more networks is internet work!!
Hope this helps
4 0
2 years ago
What is meant by Program Memory is paged?
atroni [7]

Answer:

Program memory is paged, this statement is defined as in a computer system paged memory is the process of allocation of memory and storing a portion of a process of execution. Page is a unit of logical memory in a program. It follows the process of paging, as it is a method of writing an information and reading the output from the storage drive. The main advantage of this process is that it become easy to swap because everything is the same size.

7 0
3 years ago
Other questions:
  • Which social networking function came first?
    9·2 answers
  • Part 3a. Largest power of two less than (10 pts) Implement the method public static int largestPow2LessThan(int n) which calcula
    5·1 answer
  • 2. Fabulously Fit offers memberships for
    9·1 answer
  • What do you have to do to see the html code on a website?
    15·2 answers
  • A file to which information is written is referred to as a(n) ____ file.
    8·1 answer
  • Computer-aided design software is used primarily by:
    13·1 answer
  • Which of the following is considered part of the process in the systems thinking example of a TPS?
    6·1 answer
  • Here is what my rob-lox user USED to look like, btw what is better, Samsung or apple?
    13·2 answers
  • A drive is small enough to be carried in one's pocket.
    6·1 answer
  • What is Frederick Taylor attributed to doing
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!