Я попытался понять ваш код и придумал другую реализацию:
import random
import time
buyers = (
("Peggy Carter", 10000),
("Phil Coulson", 7500),
("Edwin Jarvis", 5000),
("Justin Hammer", 2300),
("Darcy Lewis", 1750),
("Christine Everhart", 6490),
)
auctioned_item = "The Tesseract"
current_offer = random.randint(1, 5000)
print(f"The starting price for {auctioned_item} is £{current_offer}")
current_buyer = None
def auction_rounds(current_offer, buyers):
current_buyer = None
outbid = False
while not outbid:
(next_buyer, next_maximum) = random.choice(buyers)
while next_buyer == current_buyer:
(next_buyer, next_maximum) = random.choice(buyers)
outbid = current_offer > next_maximum
if not outbid:
current_buyer = next_buyer
yield (current_buyer, current_offer)
next_offer = random.randint(current_offer, min(current_offer + 500,
next_maximum))
current_buyer, current_offer = next_buyer, next_offer
else:
print(f'This is too much for {next_buyer}')
for (current_buyer, current_offer) in auction_rounds(current_offer, buyers):
print(f"{current_buyer} is offering to pay £{current_offer}",
"for", auctioned_item)
#time.sleep(3)
if current_buyer is None:
print("The first buyer wasn't even able to pay the starting price")
else:
print(f"Sold! The auction item ({auctioned_item}) is awarded to {current_buyer} for £{current_offer}")
Надеюсь, это что-то вроде того, что вы искали.