$30
CSC 242: Introduction to Computer Science II
Lab exercise Week 2
Logistics
These exercises should be completed during the lab. In order to receive full credit for the lab,
you must attend the session, remain in the lab for at least 45 minutes, and submit a file that
contains solutions to all these exercises.
You are encouraged to work in groups on lab exercises. If you do work with someone, you must
include the name(s) of your collaborator(s) at the top of the file you submit. For more
information about collaboration policies in this class, see the Academic Integrity Policy.
If you complete the lab exercise early, please read Chapters 7 and 8 in the textbook and work on
the second assignment. You are only allowed to work on assignments with at most two-other
people, either directly or indirectly, who must be formally identified as part of your assignment
submission. Please see the assignment description and the course Academic Integrity policy for
the full description of the process you must follow when completing assignments. If you need
additional help on the assignment, please ask the lab assistant.
Begin the lab by downloading the zip file found on the D2L site. It contains a template file
csc242lab2.py.
1. 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:
2. Implement the function rollDice() that takes as a parameter how many times the function
will roll two dice and how many sides those two dice have. You must create and reuse
two instances of the Die class from part 1.
The format of the output is the number of the roll, followed by a colon, the face value of
die 1 followed by a dash followed by the face value of die 2.
Here is an example of usage.
Submitting the exercises
You must submit your solution to the exercises using the lab 2 dropbox on the D2L site. Submit
only a single text file (csc242lab2.py) with each of the completed functions and classes for the
lab exercises in it. Submissions after the deadline listed above will be automatically rejected by
the system. See the syllabus for the grading policy.
Grading
The lab session is worth 10 points.
If you complete the lab exercises before the end of the lab session, please work on the second
assignment. Remember that the rules for collaboration on assignments is different from labs.
Please review the Academic Integrity pledge for more information. If you have questions about
the assignment, please ask the teaching assistant for help.