forked from AseanK/python-tools-and-games
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauction.py
More file actions
74 lines (57 loc) · 1.62 KB
/
Copy pathauction.py
File metadata and controls
74 lines (57 loc) · 1.62 KB
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
import os
from sys import platform
from ascii_art import logo
# Clears command line
def clear():
if platform == "linux" or platform == "linux2":
# linux
os.system("clear")
elif platform == "darwin":
# OS X
os.system("clear")
elif platform == "win32":
# Windows...
os.system("CLS")
# Global Val
players = {}
# Calculates average of total and selects winner
def calcBid(players):
totalBid = []
totalValue = 0
for i in players:
totalBid.append(players[i])
totalValue += players[i]
mean = totalValue / len(players)
winnerBid = min(totalBid, key=lambda x:abs(x-mean))
nameList = list(players.keys())
bidList = list(players.values())
position = bidList.index(winnerBid)
winnerName = nameList[position]
for i in players:
print(f"{i} bid ${players[i]}")
print(f"\nThe average of total comes to {mean}")
print(f"Winner is {winnerName} with ${winnerBid}!!\n\n")
clear()
print(logo)
# Adds player
bidding = True
while bidding:
name = input("Enter your name\n")
while True:
bidAmount = input("Enter the bidding amount\n$")
if bidAmount.isdigit():
bidAmount = int(bidAmount)
if bidAmount > 0:
break
else:
print("You have to bid more than $0")
else:
print(f"{bidAmount} is not a number")
players[name] = bidAmount
cont = (input("Add another player?\nEnter 'Yes' or 'No'\n")).lower()
clear()
if cont == "yes":
continue
if cont == "no":
bidding = False
calcBid(players)