Skip to content

Commit 517ce8e

Browse files
committed
improved
1 parent 1ae3b03 commit 517ce8e

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

Extrapack ZIP file.zip

2.13 KB
Binary file not shown.

Modules and Packages ZIP file.zip

2.21 KB
Binary file not shown.

p3-errors-exceptionhandling.pdf

169 KB
Binary file not shown.

string functions.pdf

259 KB
Binary file not shown.

wheel-of-python.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import random
33
import time
44
import sys
5-
sys.setExecutionLimit(600000) # let this take up to 10 minutes
5+
#sys.setExecutionLimit(600000) # let this take up to 10 minutes
66

77
# PASTE YOUR WOFPlayer CLASS (from part A) HERE
88
class WOFPlayer:
@@ -106,20 +106,26 @@ def getNumberBetween(prompt, min, max):
106106
# { "type": "bankrupt", "text": "Bankrupt", "prize": false },
107107
# { "type": "loseturn", "text": "Lose a turn", "prize": false }
108108
def spinWheel():
109-
with open("wheel.json", 'r') as f:
110-
wheel = json.loads(f.read())
109+
try:
110+
with open("wheel.json", 'r') as f:
111+
wheel = json.loads(f.read())
112+
return random.choice(wheel)
113+
except:
114+
wheel = [{ "type": "cash", "text": "$950", "value": 950, "prize": "A trip to Ann Arbor!" }, { "type": "bankrupt", "text": "Bankrupt", "prize": False }, { "type": "loseturn", "text": "Lose a turn", "prize": False }]
111115
return random.choice(wheel)
112116

113117
# Returns a category & phrase (as a tuple) to guess
114118
# Example:
115119
# ("Artist & Song", "Whitney Houston's I Will Always Love You")
116120
def getRandomCategoryAndPhrase():
117-
with open("phrases.json", 'r') as f:
118-
phrases = json.loads(f.read())
121+
try:
122+
with open("phrases.json", 'r') as f:
123+
phrases = json.loads(f.read())
119124

120-
category = random.choice(list(phrases.keys()))
121-
phrase = random.choice(phrases[category])
122-
return (category, phrase.upper())
125+
category = random.choice(list(phrases.keys()))
126+
phrase = random.choice(phrases[category])
127+
return (category, phrase.upper())
128+
except: return ("Artist & Song", "Whitney Houston's I Will Always Love You")
123129

124130
# Given a phrase and a list of guessed letters, returns an obscured version
125131
# Example:
@@ -148,16 +154,16 @@ def showBoard(category, obscuredPhrase, guessed):
148154
print('='*15)
149155
print('')
150156

151-
num_human = getNumberBetween('How many human players?', 0, 10)
157+
num_human = getNumberBetween('How many human players? ', 0, 10)
152158

153159
# Create the human player instances
154-
human_players = [WOFHumanPlayer(input('Enter the name for human player #{}'.format(i+1))) for i in range(num_human)]
160+
human_players = [WOFHumanPlayer(input('Enter the name for human player #{} '.format(i+1))) for i in range(num_human)]
155161

156-
num_computer = getNumberBetween('How many computer players?', 0, 10)
162+
num_computer = getNumberBetween('How many computer players? ', 0, 10)
157163

158164
# If there are computer players, ask how difficult they should be
159165
if num_computer >= 1:
160-
difficulty = getNumberBetween('What difficulty for the computers? (1-10)', 1, 10)
166+
difficulty = getNumberBetween('What difficulty for the computers? (1-10) ', 1, 10)
161167

162168
# Create the computer player instances
163169
computer_players = [WOFComputerPlayer('Computer {}'.format(i+1), difficulty) for i in range(num_computer)]

0 commit comments

Comments
 (0)