Question: python2.7 1. (10 points) Implement a class Die (that is a subclass of the object class) representing a Die with many sides, default of 6.

python2.7
1. (10 points) Implement a class Die (that is a subclass of the object class) representing a Die with many sides, default of 6. You need to implement a ball with supporting six methods:
a. init () which takes 1 optional parameter or initializes the Die to 6 sides.
b. roll() randomly chooses a new value for the die. The value is stored within the object.
c. get() - which returns the value of the die.
d. numSides() returns how many sides the die has.
e. str () which returns a friendly string with the value showing on the die.
f. repr (): Phyton representation of the die.
The following shows how the Die class and its methods could be used:
class Die(object):
'a class representing a Die'
def __init__(self, sides=6):
'initialize a die, default 6 sides'
pass
def roll(self):
'roll the dice'
pass
def get(self):
'get the current value of the die'
pass
def numSides(self):
'get the number of sides of the die'
pass
def __str__(self):
'get the string representation of the die'
pass
def __repr__(self):
'get the python representation of the die'
pass
 python2.7 1. (10 points) Implement a class Die (that is a

>>> dl-Die () >>>d2-Die (30) >>> dl.numSides () >>> d2.numSides () 30 >>> dl.roll() >>>dl.get ) >>>dl.roll () >>>dl.get () 1 >>>d2.roll () >>>d2.get ) 15 >>>d2.get () 15 >>> dl Die (6) >>>d2 Die (30) >>>str (dl) >>>str (d2) 30

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!