Adding assessment

This commit is contained in:
Chris Proctor 2024-03-01 18:10:43 -05:00
parent 055f163409
commit bd2d7b8f0b
1 changed files with 57 additions and 0 deletions

57
assessment.md Normal file
View File

@ -0,0 +1,57 @@
# Dice Lab Assessment
Everything works as expected. Nice work!
## Comments
I thought your observation that "This method of problem solving is more
organized than how I would have written a Yahtzee program using
my past experience" was interesting. I agree, though it's certainly possible to write
OOP badly, and thereby increase the complexity of a problem :)
I find that I increasingly think deeply about whether to use an OO approach
or a functional approach--basically, whether to focus on nouns or verbs.
Your decision to count 3- and 4-of-a-kind with a zero-initialized
dict works well:
```
of_each_counter={1:0, 2:0, 3:0, 4:0, 5:0, 6:0}
```
Two alternatives from the standard library are worth keeping in mind for
the future. A Counter just takes a list and counts instances of each value.
```
>>> from collections import Counter
>>> counter = Counter([1, 3, 3, 5, 3])
>>> print(counter)
Counter({3: 3, 1: 1, 5: 1})
```
A defaultdict is like a normal dict, but when you first access a key, its value is
initialized for you if it's not already present.
```
>>> from collections import defaultdict
>>> counts = defaultdict(int)
>>> for face in die_faces:
... counts[face] += 1
```
Another "pythonic" trick would be available for GoalYahtzee, where you check whether
all the dice faces are the same:
```
for die in dice:
if die!=dice[0].face:
flag=False
```
In this case, I'll often convert the list into a set, which enforces member uniqueness.
```
unique_faces = set(dice)
if len(unique_faces) == 1:
print("Yahtzee!")
```