12/7/2011 CS Using Die Object
12/7/2011 CS Using Die Object
12/7/2011
Matthew Carlberg
Using Objects
In this assignment, you will use an object representing a multi-sided die. The MSDie
class deIinition is shown below and can be Iound on Dropbox ~ Python Resources ~ Unit
4 Code ~ MSDie.py. You DO NOT have to change the class deIinition in any way Ior
this homework.
Irom random import randrange
class MSDie:
deI init(selI, sides):
selI.sides sides
selI.value 1
deI roll(selI):
selI.value randrange(1,selI.sides1)
deI getValue(selI):
return selI.value
deI setValue(selI, value):
selI.value value
Assignment: Your job is to add two Iunctions AFTER (outside oI) the class deIinition
that use MSDie objects. In each Iunction, you must create at least one instance oI an
MSDie object.
1. makeRandomCode(n, m). Exact same implementation as your project
makeRandomCode, except using an MSDie object to choose your random
numbers.
2. rollsUntilSeven(). This Iunction rolls TWO dice at a time, counting how many
rolls are required until the two dice ADD UP TO 7. You will need a while loop to
do this. (http://docs.python.org/tutorial/introduction.html#Iirst-steps-towards-
programming has a good example oI a while loop)