Question 5 Look at the class definition of Die class: 4 pts class Die: def _init_(self):...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Question 5 Look at the class definition of Die class: 4 pts class Die: def _init_(self): self._value = 1 def getValue(self): return self._value def roll (self): self._value = random.randrange (1, 7) Make minimal changes to the Die class definition so that the number of sides of the Die can be optionally set in the constructor with the default value of 6. For example, die8 = Die(8) will create an 8-sided die such that every time die8.roll() is called, it sets the __value to a random number between 1 and 8. Note that die = Die() should continue to create a 6-sided die. Question 6 Suppose myData is defined as follows: myData = { [1, 2, 3], 'y' : { 'color': 'blue', 'weight' : 10, 3: (7,8), }, ('a', 'b'): 4, 'z' [123, 456] } Give an expression involving myData that accesses the value 10: Give an expression involving myData that accesses the value 4: 4 pts Question 5 Look at the class definition of Die class: 4 pts class Die: def _init_(self): self._value = 1 def getValue(self): return self._value def roll (self): self._value = random.randrange (1, 7) Make minimal changes to the Die class definition so that the number of sides of the Die can be optionally set in the constructor with the default value of 6. For example, die8 = Die(8) will create an 8-sided die such that every time die8.roll() is called, it sets the __value to a random number between 1 and 8. Note that die = Die() should continue to create a 6-sided die. Question 6 Suppose myData is defined as follows: myData = { [1, 2, 3], 'y' : { 'color': 'blue', 'weight' : 10, 3: (7,8), }, ('a', 'b'): 4, 'z' [123, 456] } Give an expression involving myData that accesses the value 10: Give an expression involving myData that accesses the value 4: 4 pts
Expert Answer:
Answer rating: 100% (QA)
For Question 5 To modify the Die class definition to allow the number of sides to ... View the full answer
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
Predictive text entry systems are familiar on touch screens and mobile phones. This question asks you to consider how the same principles might be used in a programming editor for creating Java code....
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
From the information below, 1. List of the working capital accounts. 2. Calculate the net working capital. Buildings $100,000 Cash ... 5,000 Trade receivables ... 25,000 Trade and other payables .....
-
Which balance-related audit objectives are not affected by control risk for classes of transactions? Why?
-
A wise observer once said that bad writing makes smart people look dumb. Do you agree or disagree, and why?
-
Calculate the energy density versus temperature very early in the universe when the temperatures were above \(k T=300 \mathrm{MeV}\). At those temperatures, quarks and gluons were released from...
-
English Motors, Ltd. (EML), developed a new all-wheel-drive sports utility vehicle. As part of the marketing campaign, EML produced a video tape sales presentation to send to both owners of current...
-
A beam of light travels from a vacuum into water at an angle of 45. The light has a frequency of 6.00 x 1014 Hz and travels at a speed of 2.26 x 108 m/s in water. The speed of light in a vacuum is...
-
The marketing system has been accused of adding to several "evils" in society at large. Advertising has been a special target of many of these accusations. People claim that advertising creates false...
-
Design a Tips class that calculates the gratuity on a restaurant meal. Its only class member variable, taxRate, should be set by a one-parameter constructor to whatever rate is passed to it when a...
-
(a) List THREE ways energy is stored in pure graphite. (b) Explain why heat capacity at constant pressure, Cp, is always higher than the heat capacity at constant volume, Cv. (c) Write out a...
-
How much is the taxable net income using optional standard deduction ? How much is the deductible pension contributions for 2022? How much is the taxable net income using itemized deduction?...
-
Convert the following C++ program into Pep/9: #include using namespace std; const int amount = 20000; int num; int sum; int main() { cin>>num; sum = num + amount; cout < < "sum = " < < sum < < endl;...
-
The Drama Club ordered 18 pizzas for a party. Each pizza had 8 slices. Lisa ate 9 of the slices. How many slices were left for the rest of the club?
-
using the given letters, translate the statement into symbolic form. 1) Alaskan is sweet only if neither Heineken is balanced nor Pabst is clean tasting. Let A = Alaskan is sweet, H = Heineken is...
-
What are the two methods used to translate financial statements and how does the functional currency play a role in determining which method is used?
-
Write a program showing that a method with its own try block does not have to catch every possible error generated within the try. Some exceptions can slip through to, and be handled in, other scopes.
-
Create a mortgage calculator app that allows the user to enter a purchase price, down-payment amount and an interest rate. Based on these values, the app should calculate the loan amount (purchase...
-
Write an application that reads an integer and determines and prints whether its divisible by 3 or not. Use the remainder operator. A number is divisible by 3 if its divided by 3 with a remainder of...
-
Select an information system with which you are familiar, and which you feel needs to be improved, based upon your experiences as an employee, customer, other system user, or system owner, Switch...
-
You have learned the importance of making sure that requirements are correctly identified. Hut how do you know when you have a correct requirement-that is, what criteria must each requirement meet in...
-
Prepare a full feasibility analysis, including Economic, Operational, Schedule, Legal, and Technical analyses for the system you are suggesting in problem 1. Your analysis should be no more than 30...
Study smarter with the SolutionInn App