-
Notifications
You must be signed in to change notification settings - Fork 9
/
auction_program.py
78 lines (50 loc) · 1.56 KB
/
auction_program.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Auction_Program
import os
import sys
sys.path.extend([os.path.join(os.getcwd(), 'src'), os.path.join(os.getcwd())])
import random
from day_9.auction import Auction
from day_9.logo import LOGO
from utility import clear_console
def get_random_bid(start=1, end=2000):
return random.randint(start, end)
def get_random_name_and_remove_it_from(names):
name = random.choice(names)
names.remove(name)
return name
def create_default_bidders():
names = ["John", "Harry", "Joe", "Tony", "Emma", "Mia"]
bidders_list = [{
get_random_name_and_remove_it_from(names): get_random_bid()
for i in range(6)
}]
return bidders_list
def get_default_bidders():
temp = {}
for b in create_default_bidders():
temp.update(b)
return temp
def user_interface():
auction = Auction()
print(auction.get_welcome_message())
auction.name_with_bid_amount_map = get_default_bidders()
name_bid_amount = auction.name_with_bid_amount_map
while True:
auction.print_current_bidders()
user_name = auction.get_user_name()
user_bid = auction.get_user_bid_amount()
name_bid_amount[user_name] = user_bid
answer = auction.ask_user_more_biders()
if answer == 'n':
break
clear_console()
winner, winner_bid = auction.get_winner(name_bid_amount)
print(f"The winner is {winner} with a bid of ${winner_bid:,}")
def main():
print(LOGO)
try:
user_interface()
except KeyboardInterrupt:
print("Exit")
if __name__ == "__main__":
main()