Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the __init__ function take in two positional arguments material and summon. These are Metal and False by default. - make function called generate_probabilities which

 Modify the __init__ function take in two positional arguments material and summon. These are Metal and False by default.

- make function called generate_probabilities which has two parameters - material_type, and summon to represent the type of material that the container is armed with and whether the container is summoned. The keyword argument summon has a default value of False. The function returns a tuple with dimension 1 x 6 representing the probabilities of not generating a bottle and generating each type of bottle as given in the table. If the material_type is Glass and the container is summoned, the probability for a Red bottle must be increased accordingly by 0.25.

- Modify the codes in the function get_user_in to call generate_probabilities. The function must now take in two arguments material and summon which represent the type of material that the container is armed with and whether the container is summoned in order to pass these values to function. The arguments have a default value of Metal and False.

- make function called generate_cap which takes in a string object which represents the type of bottle and returns a string object cap. You will need to update the Bottle class accordingly to call the appropriate functions. The UML diagram of your updated Bottle class should now look like this:

Bottle

name: str

money: int

points: int

cap: str

 

table:

The table indicates the probability of catching each type of

bottle. some have better attraction rates

type of materialatrract rate%RedYellowBlueWhiteGreen
Metal500.10.150.10.10.05
Marble400.050.20.050.020.08
Glass300.010.050.050.040.15

 

  import random     def get_user_in():     generate = random.random()     if generate >= 0 and generate < 0.50:         bottle_input = None     elif generate >= 0.50 and generate < 0.60:         bottle_input = "Red"     elif generate >= 0.60 and generate < 0.70:         bottle_input = "Yellow"     elif generate >= 0.70 and generate < 0.80:         bottle_input = "Blue"     elif generate >= 0.80 and generate < 0.90:         bottle_input = "White"     elif generate >= 0.90 and generate < 1:         bottle_input = "Green"     return bottle_input     def match_to_table(bottle_type: str | None) -> tuple:     '''     money and points for different bottle colours     Parameter:         bottle_type: str | None     Returns:         money:       int, amount of money         points:     int, amount of points given     '''     table_values = [(None, 0, 0), ("Red", 100, 115), ("Yellow", 200, 200), ("Blue", 125, 100), ("White", 100, 90), ("Green", 300, 200)]     for row in table_values:         if row[0] == bottle_type:             money = row[1]             points = row[2]             break     return (money, points)     class Bottle:     def __init__(self):         self.generate_bottle()         self.money, self.points = self.match_to_table(self.bottle_input)       def generate_bottle(self):         self.bottle_input = get_user_in()       def match_to_table(self, bottle_type: str | None) -> tuple:         money, points = match_to_table(bottle_type)         return money, points       def get_bottle_name(self) -> str:         return self.bottle_input       def get_money(self) -> int:         return self.money       def get_points(self) -> int:         return self.points       def __str__(self) -> str:         return self.get_bottle_name()

Step by Step Solution

3.38 Rating (151 Votes )

There are 3 Steps involved in it

Step: 1

Answer Heres the modified code with the requested changes import random def getuserinmaterialMetal s... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Elements Of Chemical Reaction Engineering

Authors: H. Fogler

6th Edition

013548622X, 978-0135486221

More Books

Students also viewed these Operating System questions