Answer:
1)
Add this while statement to the code:
while(keep_going!='n'):
#the program keeps asking user to continue bidding until the user enter 'n' to stop.
2)
Here is the code for ACTIVITY 53.3. While loop: Insect growth:
num_insects = int(input())
while num_insects <= 100:
print(num_insects, end=' ')
num_insects = num_insects * 2
Step-by-step explanation:
Here is the complete code for 1)
import random
random.seed (5)
keep_going='-'
next_bid = 0
while(keep_going!='n'):
next_bid = next_bid + random.randint(1, 10)
print('I\'ll bid $%d!' % (next_bid))
print('continue bidding?', end='')
keep_going = input()
Here the the variable keep_going is initialized to a character dash keep_going='-'
The statement keep_going = input() has an input() function which is used to take input from user and this input value entered by user is stored in keep_going variable. while(keep_going!='n'): is a while loop that keeps iterating until keep_going is not equal to 'n'. print('continue bidding?', end='') statement prints the continue bidding? message on the output screen. For example the user enters 'y' when this message appears on screen. So keep_going = 'y' . So the operation in this statement next_bid = next_bid + random.randint(1, 10) is executed in which next_bid is added to some randomly generated integer within the range of 1 to 10 and print('I\'ll bid $%d!' % (next_bid)) prints the result on the screen. Then the user is prompted again to continue biffing. Lets say user enters 'n' this time. So keep_going = 'n'. Now the while loop breaks when user enters 'n' and the program ends.
2)
num_insects = int(input()) #the user is prompted to input an integer
while num_insects <= 100: #the loop keeps iterating until value of num_insects exceeds 100
print(num_insects, end=' ') #prints the value of num_insects
num_insects = num_insects * 2 #the value of num_insects is doubled
For example user enters 8. So
num_insects = 8
Now the while loop checks if this value is less than or equal to 100. This is true because 8 is less than 100. So the body of while loop executes:
print(num_insects, end=' ') statement prints the value of num_insects
So 8 is printed on the screen.
num_insects = num_insects * 2 statement doubles the value of num_insects So this becomes:
num_insects = 8 * 2
num_insects = 16
Now while loop checks if 16 is less than 100 which is again true so next 16 is printed on the output screen and doubled as:
num_insects = 16 * 2
num_insects = 32
Now while loop checks if 32 is less than 100 which is again true so next 32 is printed on the output screen and doubled as:
num_insects = 32 * 2
num_insects = 64
Now while loop checks if 64 is less than 100 which is again true so next 64 is printed on the output screen and doubled as:
num_insects = 64 * 2
num_insects = 128
Now while loop checks if 128 is less than 100 which is false so the program stops and the output is:
8 16 32 64
The programs along with their output is attached.