Files
  • main.py
main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# This program calculates the "Deals" for the Skittles deal or no deal game

import time, types

cases = [0, 1, 5, 10, 25, 50, 100, 200, 300, 600]
starting_case_count = len(cases)

def make_an_offer(cases_left):
	"""
	Makes an offer based on what is left
	Offer becomes greater and greater percent of EV as fewer cases are left
	"""
	#how many cases are left
	count_of_cases = float(len(cases_left))
	
	#expected skittles
	ev_skittles = 0.0
	
	#Expected skittles (EV)
	for i in cases_left:
		ev_skittles += (1/count_of_cases)*i
	
	#govenor scales the percent of the EV that is offered
	#Starts at .2 and climbs to .9 
	#the fewer cases the better the deal	
	govenor = .9 - ((.5   / starting_case_count) * float(len(cases)))
	offer = int(govenor * ev_skittles)
	
	#Displays message of new deal
	print ' '
	print ' '
	print 'Calculating offer based on cases left:'
	print cases
	time.sleep(1)
	print '...'
	time.sleep(1)
	print '...'
	time.sleep(1)
	print 'I am prepared to offer you...'
	time.sleep(3)
	print ' '
	print '%s skittles. Deal OR no deal!?!?' % offer
	print ' '

def get_ans():
	"""
	Returns True if the game continues
	Else False
	"""
	
	question = raw_input('"Deal" or "No Deal"?:')
	
	if question == "Deal":
		print 'Congratulations on a good game'
		return False
	elif question == "No Deal":
		return True
	else: 
		print 'Invalid input'
		get_ans()	
	
	return True
	
def getInteger(prompt):
    while True:
        userIn = raw_input(prompt)
        try:
            return int(userIn)
        except ValueError:
            print "That is not an integer"

def update_cases():
	"""
	Asks what case is drawn and then updates the global variable
	"""
	print 'Here are the cases that are left'
	print ' '
	print cases
	print ' '
	
	global cases
	
	case_ans = getInteger('What case was opened?:')
	
	if case_ans in cases:
		cases.remove(case_ans)
	else: 
		print "Not a valid case to open"
		update_cases()

def the_game():
	make_an_offer(cases)
	if get_ans() == True:
		update_cases()
		the_game()
	else: return
	print "Thanks for playing!"
	

# <--------------------------------------Run it------------>	
the_game()