/A-Dice-Roller

Worksheet 7 OOP A Dice Roller

Primary LanguagePython

July 2022 Computing programming course by Teesside University

Worksheet 7-Object-Oriented Programming

[ASSESSMENT] Question 4: A Dice Roller (class_roll.py) Let’s now implement a dice roller as a reusable program component in the spirit of the previous question.

  1. Create a new class called DiceRoller with a constructor that takes 1 argument num_of_dice that it stores as an attribute.
  2. Now, add a function to your class called roll() that rolls num_of_dice dice and returns the value of the roll. For example, if num_of_dice is 2, then 2 random numbers between 1 and 6 are generated, added together and returned as a value from 2-12.
  3. Now, add another function to your class called roll_many() that takes an argument n and returns a list containing the results of calling roll() n times.
  4. As for question 3, from your week 3 exercise on dice rolling, copy your solution across and integrate your new reusable DiceRoller class, imported from a separate file as before.