Deal or No Deal - Starter Code
unknown
python
2 years ago
1.7 kB
25
Indexable
import random
dollars = [.01, 1, 5, 10, 25, 50, 75, 100,
200, 300, 400, 500, 750, 1000,
5000, 10000, 25000, 50000, 75000,
100000, 200000, 300000, 400000,
500000, 750000, 1000000]
random.shuffle(dollars)
cases = list(range(1, len(dollars)+1))
def getChoice():
''' return int
Check user's input until the user picks an available case
'''
while True:
choice = int(input("\nPick a case: "))
if choice in cases:
return choice
else:
print("invalid choice")
def displayList(message, numList):
'''(str, list) -> str
Display a message and a list of items separated by |
'''
result = "|"
for x in numList:
result += str(x) + "|"
return(message + "\n" + result)
numToPick = len(cases)//4
percentage = .2
answer = "no deal"
while len(cases)>1 and answer.lower() != "deal":
for i in range(0, numToPick):
print(displayList("availalble cases:", cases))
print(displayList("remaining prizes:", sorted(dollars)))
choice = getChoice()
loc = cases.index(choice)
print(cases.pop(loc), "holds", dollars.pop(loc))
if len(cases) == 1:
print("\nTime to open your final case!")
break
if numToPick > 1:
numToPick -= 1
offer = int(sum(dollars)/len(cases)*percentage)
percentage += .07
print("\n\n\nBanker offer:", offer)
answer = input("Deal or no deal? ")
if len(cases) == 1:
print("\nYou just won", dollars[0], "dollars!")
else:
print("\nYou just won", offer, "dollars!")Editor is loading...
Leave a Comment