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
4-One possible performance multiplication enhancement is to do a shift and add instead of an actual multiplication. Since 9 * 6,
pychu [463]

Answer:

Check the explanation

Explanation:

The above question can be sovled in the below step by step way:

15 can be written as 16-1 = 24 -1

Therefore, 15 *13 = (24 -1)*13

= 13*24 - 13

Now, when we left shift a number we multiply it by 2k .Where k is no of times we left shifted it.

Therefore, 13*24 = shift 13 to left 4 times

15 * 13 = shift 13 to left 4 times and subtract 13 from it.

3 0
3 years ago
Which of the following statements represents the number of columns in a regular two-dimensional array named values?
puteri [66]

Answer:

(a) values[0].length

Explanation:

In programming languages such as Java, an array is a collection of data of the same type. For example, a and b below are an example of an array.

a = {5, 6, 7, 9}

b = {{2,3,4}, {3,5,4}, {6,8,5}, {1,4,6}}

But while a is a one-dimensional array, b is a regular two-dimensional array. A two-dimensional array is typically an array of one-dimensional arrays.

Now, a few thing to note about a two-dimensional array:

(i) The number of rows in a 2-dimensional array is given by;

<em>arrayname.length</em>

For example, to get the number of rows in array b above, we simply write;

<em>b.length </em>which will give 4

(ii) The number of columns in a 2-dimensional array is given by;

<em>arrayname[0].length</em>

This is with an assumption that all rows have same number of columns.

To get the number of columns in array b above, we simply write;

<em>b[0].length </em>which will give 3

Therefore, for a regular two-dimensional array named values, the number of columns is represented by: values[0].length

5 0
3 years ago
How much time does a gold chest take to open
MaRussiya [10]

Gold chest takes 8 hours to open or unlock.

<u>Explanation:</u>

Clash royale is a game which has been developed and published with the help of a super cell. It is a video game. Many players can play this game at the same time. In the sense, clash royale is a multi player game.

In this game, the players who are playing the game are awarded with the gold chest. They are also awarded with the gems. In order to unlock or open a gold chest eight hours are needed. Apart from this there is an other way also with which the gold chest can be unlocked. It can be unlocked with the help of forty eight gems.

7 0
3 years ago
Select the most likely outcome of making only on-time minimum payments to a credit
Serjik [45]
The answer is B. Your will have gone mostly towards paying interest and you will still owe the majority of the balance that you had from ago
4 0
3 years ago
What is the name of the technology that integrates vast data bases with georeferenced data in order to design, plan, and manage
ivanzaharov [21]

Answer:

"Geographic information systems " is the right answer.

Explanation:

  • This is indeed a computer-based method for observing and analyzing current events that are happening on the planet. GIS could enhance teaching and learning begin to understand geographical trends and regularities by relaying completely unconnected information.
  • It represent an experimental field and while the GIS supplier government offers us modern, improved, and quicker technical resources for the computer hardware.
7 0
3 years ago
Other questions:
  • Which best describes inserting a table using the Table Gallery
    10·2 answers
  • How do i unblock website on my school computer
    7·2 answers
  • What is the maximum upload speed you can get on an isdl internet connection?
    9·1 answer
  • An electronic spreadsheet is a type of<br> archive.<br> database.<br> document.<br> periodical.
    15·2 answers
  • To rename a database object, press and hold or right-click the object in the navigation pane and then tap or click ____ on the s
    10·1 answer
  • _____ are independent and not associated with the marketing efforts of any particular company or brand.​
    9·1 answer
  • Which of the following are mass communication methods? (Select all that apply.)
    9·1 answer
  • If you want to present slides to fellow students your coworkers which productivity software should you use to create them
    15·2 answers
  • Assume that x and y are boolean variables and have been properly initialized. !(x || y) || (x || y) The result of evaluating the
    10·1 answer
  • Can you please help me with this crossword puzzle, I am having trouble with numbers 5 down and 22 across.
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!