173k views
3 votes
Write an expression that continues to bid until the user enters 'n'. Sample output with inputs: 'y' 'y' 'n' I'll bid $7! Continue bidding? I'll bid $15! Continue bidding? I'll bid $23! Continue bidding?

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 ${}!'.format(next_bid))
print('Continue bidding?', end=' ')
keep_going = input()

User Snovity
by
8.0k points

1 Answer

3 votes

Final answer:

The question involves creating a Python code snippet that continuously increments a bid amount until the user inputs 'n'. It uses a while loop for the iteration and random. randint for generating the bid increments.

Step-by-step explanation:

The question is about writing a Python code snippet that updates a bidding process until the user decides to stop by entering 'n'. The code should continue prompting the user with "Continue bidding?" after each new bid is made. An initial bid is generated and then incremented by a random amount selected between 1 to 10, which are added to the current bid in a loop until the user inputs 'n'.

The provided code correctly initializes the bidding process, enters a loop, increments the bid by a random amount, prints the current bid, and prompts the user to continue or stop the bidding. Variables keep_going is set as a control variable for continuing the loop, and next_bid keeps track of the current bid amount.

User Colin Jack
by
8.1k points