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
Yakvenalex [24]
3 years ago
6

Given positive integer num_insects, write a while loop that prints that number doubled up to, but without exceeding 100. Follow

each number with a space.
Sample output with input: 8
8 16 32 64
Here's what I havenum_insects = 8 # Must be >= 1print(num_insects, '', end='')while num_insects <= 100 : num_insects = num_insects * 2 print(num_insects,'', end="")This code prints the number 128 even thought the loop is set to end after 100? Why is that?
Computers and Technology
1 answer:
grandymaker [24]3 years ago
8 0

Answer:

The while loop is executed one more time when num_insects is 64. It gets doubled and 128 gets printed. Then the while loop is not executed anymore since 128 exceeds 100.

So the reason you see 128 is because the multiplication by 2 happens inside the loop before you print. You enter it with 64, but by the time you get to the print statement, it was already multiplied.

The solution is to switch the print and the multiply:

num_insects = 8 # Must be >= 1

while num_insects <= 100 :

   print(num_insects,'', end="")

   num_insects = num_insects * 2

This has one added advantage that the very first print statement outside the loop can be removed.

You might be interested in
Rhea has been asked to interview the new CEO of an energy company. She has scheduled a meeting with him in the company’s meeting
vovikov84 [41]
The correct answer would be B
7 0
3 years ago
Read 2 more answers
Help? Can you explain what this mean?
Pani-rosa [81]

Death by PowerPoint simply refers to a phenomenon that's caused as a result of the poor use of a presentation software.

It should be noted that the phrase was coined by Angela Garber. It simply means when an individual uses the presentation software poorly.

The main contributors to death by PowerPoint include confusing graphics, slides that had too much text, etc. It's important to present one's work logically with good information.

Learn more about PowerPoint on:

brainly.com/question/25795152

3 0
2 years ago
____________________________ and _________________________ are 2 negative impacts of the internet on businesses.
Bogdan [553]

Answer:

i no you its me remember and the answer is b.

Explanation:

7 0
2 years ago
A friend has a CD of one of your favorite artists and has offered to let you copy it.
creativ13 [48]
No; copyright laws protect this artist's rights and I need to purchase the CD if I want it.  

This is due to copyrights being applied at the time of fixation.  In other words, as soon as the words or lyrics have been placed on paper, recorded or put in a computer the ARTIST is protected.
6 0
3 years ago
What is a coverage map used for
erastova [34]

Answer/Explanation:

A coverage map shows how much land something takes up or reaches to.

4 0
2 years ago
Read 2 more answers
Other questions:
  • What filter gives a “squeezed” effect to an image?
    14·2 answers
  • How would Microsoft Word inform you of the error in the sentence below? (Tip: The error is in bold.)
    7·1 answer
  • I don't know the answer and I tried different ones and they not what the book is looking for.
    7·1 answer
  • To resize columns in a subform, press and hold or right-click the subform in the navigation pane, and tap or click ____ on the s
    12·1 answer
  • What is the leading use of computers
    15·2 answers
  • Why is compression a "hard problem" for computers? Draw on your own experience compressing text with the text compression widget
    12·1 answer
  • What is the Matlab command to create a column vector with 11 equally spaced elements, whose first element is 2 and whose last is
    8·1 answer
  • How do u type faster
    5·1 answer
  • HELP PLEASE 100 POINTS
    8·2 answers
  • Read the introduction (paragraphs 1-3].
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!