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
What kind of music is liked the most by people
Varvara68 [4.7K]
A . Pop
D . K-popp I guess
6 0
4 years ago
Read 2 more answers
A manager suspects that one of his team members has been fraudulently accessing confidential and sensitive information and breac
Zigmanuir [339]

The technology that would be useful to look into the activities of the team member is the computer forensics

<h3>How to determine the technology?</h3>

Usually, when there is a case of data breach; the technology used to tackle the problem is the use of computer forensics.

This  is so because computer forensics involves identifying the storage of data on a computer system

Hence, the manager should make use of computer forensics

Read more about computer technology at:

brainly.com/question/1538272

#SPJ4

3 0
2 years ago
Read 2 more answers
The computer virus is simply a.......... a. diseases b.set of computer instrustruction or code c. types of bacteria​
Svetllana [295]

Answer: b

The computer virus is simply a ___

b. Set of computer instructions or code

4 0
3 years ago
Which statement about routers is !!!FALSE!!!
monitta

Answer:

b. they are located at the intersections of the network of wires and cables that make up the internet.

Explanation:

Given that Router is a computer networking device that operates by transferring data packets between computer networks, while also ensuring traffic organizing tasks on the Internet.

Hence, Routers put packets in the right order after they arrive at their destination by matching the destination IP address of the packet and one of the addresses in the routing table.

Also, Routers check the address on each packet that arrives and decide which way it should go next​ by ensuring the data packets are summarized for the outgoing interface recorded in the table entry.

Therefore, the correct answer is option B

8 0
3 years ago
What are the pros and cons of using the Internet for researching career information?
VikaD [51]

Answer:

pros: a lot of info

cons: a lot of it can be fake!

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • In the dewey decimal sysytem, the call number 800 notes which section
    10·1 answer
  • Mary can view the thumbnails of her presentation slides when she is creating the slides. Which element of the program’s interfac
    5·2 answers
  • Hi weegy, what is the latest android os?
    9·1 answer
  • Jamie is preparing a presentation on his laptop for his college annual event. He inserts audio and video files into the presenta
    11·2 answers
  • Show that, if n is an integer and n^3 + 5 is odd, then n is even, using:
    12·1 answer
  • Which of the following describes the pre-phase of an interview
    7·1 answer
  • Consider the following code: x = 9 y = -2 z = 2 print (x + y * z) What is output? 9 13 14 5
    5·1 answer
  • _______and ________ enables computers to communicate and it can pass information between two networks.
    15·1 answer
  • What stage of the development process is often called the pre-alpha phase and is the "meat" of the design process where features
    5·1 answer
  • What does the asterisk (*) after select tell the database to do in this query?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!