DiceSet Class in Python Write a class named DiceSet that contains a list of Die objects. Fields dice a list of Die objects Methods __init__(self, dice_faces) The constructor should instantiate the dice list to an empty list if no parameters are set. The constructor should take a list of integers. Add one die to the dice set for each integer with the number of faces equal to the integer. pop_die(self, value) Remove and return the first die with the given value from the list. add_die(self, die) Adds the given die (of class Die) to the dice list. roll(self) Roll all the die objects in the list of dice and return their sum. die_values(self) Return a list of the int values (last rolls) of the dice in the list. __str__(self) returns a string version of a dice set. Example: "{[d3] 1, [d6] 4, [d12] 5, [d4] 3}"

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question

DiceSet Class in Python

Write a class named DiceSet that contains a list of Die objects.

Fields

  • dice
    • a list of Die objects Methods
  • __init__(self, dice_faces)
    • The constructor should instantiate the dice list to an empty list if no parameters are set.
    • The constructor should take a list of integers. Add one die to the dice set for each integer with the number of faces equal to the integer.
  • pop_die(self, value)
    • Remove and return the first die with the given value from the list.
  • add_die(self, die)
    • Adds the given die (of class Die) to the dice list.
  • roll(self)
    • Roll all the die objects in the list of dice and return their sum.
  • die_values(self)
    • Return a list of the int values (last rolls) of the dice in the list.
  • __str__(self)
    • returns a string version of a dice set. Example: "{[d3] 1, [d6] 4, [d12] 5, [d4] 3}"
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT