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}"
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}"
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 2PE
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
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
Knowledge Booster
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.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT