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
The factors of power of device
LUCKY_DIMON [66]

Answer:

tfopod

Explanation:

5 0
2 years ago
Free brainliest!?! &lt;3​
Sholpan [36]

Meee plzzzzz First!............

4 0
2 years ago
Read 2 more answers
Read the paragraph.
aleksandrvk [35]

Answer:

I think sentence 3 bc it doesn't really make any sense Ik it's explaining it but it doesnt connect with the whole story as much I think it has to have more details

5 0
3 years ago
Read 2 more answers
The Healthy Nutrition Counseling Center and the Simple Solutions Software Company have recently joined forces to produce a meal
labwork [276]

Answer: (B) Strategic alliance.

Explanation:

The strategic alliance is one of the type of the agreement that help the organization for developing the effective processes. The strategic alliance basically allow associations, people or different substances to move in the direction of normal or connecting objectives.

The main advantage of the strategic alliance is that in terms of economical condition it reduces the overall, risks in the process and also reduced the costs. This technique basically include new technologies and diversifying services and the products.  

Therefore, Option (B) is correct.

5 0
3 years ago
What category of predefined formulas in Excel contains the Boolean functions?
ololo11 [35]
The predefined formulas in Excel that contain the Boolean functions fall under the Logical Functions category. The Boolean functions consist of "AND", "OR", "XOR", "NOT", "IF", "IFERROR" and "IFNA".  When you need to use an Excel Function, you can type the function into the cell. You also need to add the arguments for the function in between brackets. If the function is complex or you are a beginner user, there is a function inputting tool which will help you choose which function you require. 

5 0
3 years ago
Other questions:
  • Safety interlock module operates by monitoring the voltage from the
    7·1 answer
  • In the game Beehive, you play the role of a worker bee who must watch over her hive. Your duties include (among others) directin
    12·2 answers
  • Fullsoft, Inc. is a software development company based in New York City. Fullsoft’s software product development code is kept co
    10·1 answer
  • Question 1 (1 point)
    10·2 answers
  • Which of the following about if statement is true? A. The condition is a Boolean expression B. A Boolean expression is something
    15·1 answer
  • 5. RAM IS YOUR SYSTEM’S-
    14·2 answers
  • If you notice files being transferred to or from your computer a. Simply close the window c. Tell the lab instructor b. Open a n
    11·2 answers
  • What do we call data that's broken down into bits and sent through a network?
    15·1 answer
  • A user tells a help desk technician that their browser is displaying a message that a site can't be
    14·1 answer
  • Here is the problem specification: An Internet service provider has three different subscription packages for its customers: Pac
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!