-
Notifications
You must be signed in to change notification settings - Fork 0
/
DonGass_hw5_task4.py
55 lines (45 loc) · 1.47 KB
/
DonGass_hw5_task4.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
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 21 22:12:04 2017
@author: Don Gass
"""
toss = []
scored_toss = []
user_max = 0
max_value = 0
while True:
try:
die = int(input('Enter die (1-6) or just hit Enter to quit: '))
if die < 1 or die > 6:
print('The dice we are using have 6 sides! Try again.')
else:
toss.append(die)
continue
except ValueError:
break
while True:
try:
if toss != []:
active = int(input('Choose active die: '))
else:
break
#if toss.index(active) returns ValueError (meaning it doesn't find active
#in the list), it will jump to except ValueError clause then back to try
#clause
toss.index(active)
#calculate user score
user_max = active * toss.count(active)
#determine max possible score
for x in toss:
scored_toss.append(x * toss.count(x))
max_value = max(scored_toss)
break
except ValueError:
print('Try again! You must choose an active die from the rolled dice...', toss)
#display results
if max_value == 0:
print("Didn't feel like rolling dice?")
else:
print('Your selection was %d with a score of %d.' % (active,user_max))
if max_value > user_max:
print('You could have achieved a score of %d with a different selection!' % max_value)