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
____ allows you to add formatting such as shapes and colors to text
Alla [95]
Css also known as cascading style sheets which is a program used to design a webpage and color in the texts of a body.
6 0
4 years ago
In IDLE, which symbols are used for the prompt? <br>*** <br>&lt;&lt;&lt;<br> &gt;&gt;&gt;<br> ---​
Norma-Jean [14]

Answer: >>>

Explanation:

just finished the test and got this right

7 0
4 years ago
What formula would you enter to add the values in cells b4, b5, and b6?
Semenov [28]
=SUM(b4:b6)  If it doesn't show the $ sign just make sure it's in currency :)  I hope this helped!! Good Luck!!! :)
4 0
4 years ago
Modify this query so results are grouped by values in the DeptName field and values in the Credits field are summarized with the
docker41 [41]

Answer:

Select and group the table with the DeptName and sum the credits field from the Design Ribbon tab, click the Totals button, then click the credits field's total row, expand the Total row's Group by list, and select the Sum option and then click run.

Explanation:

Microsoft Access is a relational database platform developed by Microsoft. It is used to create a database for storing data and a means of querying the data from storage.

The result of the query can be a grouped dataset, grouping a column by the aggregate of another column. The dataset above is queried to return the grouped DeptName by the aggregate of the sum of the credits field.  

7 0
4 years ago
Write a program that reads in ten numbers from the user and displays the distinct numbers. If a number entered by the user appea
Jobisdone [24]

Answer:

Here you go :)

Explanation:

Change this however you'd like:

array = []

for n in range(10):

   x = int(input("Enter integer: "))

   array.append(x)

dup = set(array)

print(", ".join(str(i) for i in dup))

7 0
3 years ago
Other questions:
  • Word 2013 opens, by default, on a blank document?
    13·2 answers
  • Enter the value of 5⋅(13.5−4.5). <br> ​
    5·1 answer
  • Write a statement containing a logical expression that assigns true to the
    13·1 answer
  • 7. Which innovation in video games do you think has been most significant? Include at least one way that innovation affects the
    6·1 answer
  • Which is a good guideline to follow for adding animation to a presentation?. A. Use a different animation for each slide.. B. Us
    8·2 answers
  • Which tables and fields would you access to determine which book titles have been purchased by a customer and when the order shi
    15·1 answer
  • Distance Traveled The distance a vehicle travels can be calculated as follows: For example, if a train travels 40 miles per hour
    15·1 answer
  • Lucy wants to add some notes in her research paper that provide additional information to the reader. She also wants to display
    14·1 answer
  • Team members can collaborate on ideas using telepresence. <br> true or false?
    10·1 answer
  • leon started a project to design and create a new video game for the animation studio where he develops graphics and animations
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!