235k views
3 votes
1| i = 1

2| j = 100
3| while i < j:
4| [fill in the first blank]
5| [fill in the second blank]
Q: The code segment above defines a while loop. Our goal is to print and double i until it exceeds j, but not to print i once it exceeds j. With i = 1 and j = 100, for example, we want it to print 1, 2, 4, 8, 16, 32, and 64, each number on its own line.

1 Answer

4 votes

Final answer:

The code segment above defines a while loop that prints and doubles the value of 'i' until it exceeds 'j', but does not print 'i' once it exceeds 'j'.

Step-by-step explanation:

The code segment above defines a while loop that prints and doubles the value of 'i' until it exceeds 'j', but does not print 'i' once it exceeds 'j'.

To achieve this, you would fill in the first blank with 'print(i)', to print the value of 'i', and fill in the second blank with 'i = i * 2', to double the value of 'i'.

Here's how the modified code would look like:

  1. i = 1
  2. j = 100
  3. while i < j:
  4.  print(i)
  5.  i = i * 2

User Dani Mesejo
by
8.9k points

No related questions found