Refer to the following code and answer the questions on the right: 1 class Product: 2 store_name = "ProtoTop" 1. Which of the following can be used to change the stock attribute of hopia? 3 O hopia.add_supplies(20) O hopia.sell(20) O Product.add_supplies(hopia, 20) O Product.selI(hopia, 20) O hopia.stock += 20 4 def _init_(self, name, category, price, stock, weight_in_grams): self.name = name self.description = self.category = category 8 self.price = price self.stock = stock 10 self.weight_in_grams = weight_in_grams 2. What will be the output by the print function below: 11 def change_name(self, new_name): self.name = new_name hopia.change_description(f"{hopia.name} is a {hopia.category} product that weighs {hopia.weight_in_grams} grams print(hopia.description) 12 13 14 15 def change_description(self, new_description): Answer: 16 self.description = new_description 17 18 def change_category(self, new_category): 19 self.category = new_category After the last line, let us add the following assignment statement hopia.store_name = "FreshTop" 3. 20 21 def change_weight(self, new_weight_in_grams): print(hopia.store_name) 22 self.weight_in_grams = new_weight_in_grams 23 We have directly accessed and changed the value of the store_name attribute of hopia. This means that what we are printing is now an instance attribute and not a class attribute. def add_supplies(self, stocks_added): self.stock += stocks_added 24 25 O True 26 O False def sell(self, stocks_sold): if self.stock > stocks_sold: self.stock -- stocks_sold 27 28 29 30 else: 31 print(f"Not enough stocks of {self.name} for selling.") 32 33 hopia = Product("Hopia", "food", 4, 100, 20)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question
100%

Using PYTHON,

Refer to the following code and answer the questions on the right:
1 class Product:
2
store_name = "ProtoTop"
1. Which of the following can be used to change the stock attribute of hopia?
3
O hopia.add_supplies(20)
O hopia.sell(20)
O Product.add_supplies(hopia, 20)
O Product.selI(hopia, 20)
O hopia.stock += 20
4
def _init_(self, name, category, price, stock, weight_in_grams):
self.name = name
self.description =
self.category = category
8
self.price = price
self.stock = stock
10
self.weight_in_grams = weight_in_grams
2.
What will be the output by the print function below:
11
def change_name(self, new_name):
self.name = new_name
hopia.change_description(f"{hopia.name} is a {hopia.category} product that weighs {hopia.weight_in_grams} grams
print(hopia.description)
12
13
14
15
def change_description(self, new_description):
Answer:
16
self.description = new_description
17
18
def change_category(self, new_category):
19
self.category = new_category
After the last line, let us add the following assignment statement
hopia.store_name = "FreshTop"
3.
20
21
def change_weight(self, new_weight_in_grams):
print(hopia.store_name)
22
self.weight_in_grams = new_weight_in_grams
23
We have directly accessed and changed the value of the store_name attribute of hopia.
This means that what we are printing is now an instance attribute and not a class attribute.
def add_supplies(self, stocks_added):
self.stock += stocks_added
24
25
O True
26
O False
def sell(self, stocks_sold):
if self.stock > stocks_sold:
self.stock -- stocks_sold
27
28
29
30
else:
31
print(f"Not enough stocks of {self.name} for selling.")
32
33 hopia = Product("Hopia", "food", 4, 100, 20)
Transcribed Image Text:Refer to the following code and answer the questions on the right: 1 class Product: 2 store_name = "ProtoTop" 1. Which of the following can be used to change the stock attribute of hopia? 3 O hopia.add_supplies(20) O hopia.sell(20) O Product.add_supplies(hopia, 20) O Product.selI(hopia, 20) O hopia.stock += 20 4 def _init_(self, name, category, price, stock, weight_in_grams): self.name = name self.description = self.category = category 8 self.price = price self.stock = stock 10 self.weight_in_grams = weight_in_grams 2. What will be the output by the print function below: 11 def change_name(self, new_name): self.name = new_name hopia.change_description(f"{hopia.name} is a {hopia.category} product that weighs {hopia.weight_in_grams} grams print(hopia.description) 12 13 14 15 def change_description(self, new_description): Answer: 16 self.description = new_description 17 18 def change_category(self, new_category): 19 self.category = new_category After the last line, let us add the following assignment statement hopia.store_name = "FreshTop" 3. 20 21 def change_weight(self, new_weight_in_grams): print(hopia.store_name) 22 self.weight_in_grams = new_weight_in_grams 23 We have directly accessed and changed the value of the store_name attribute of hopia. This means that what we are printing is now an instance attribute and not a class attribute. def add_supplies(self, stocks_added): self.stock += stocks_added 24 25 O True 26 O False def sell(self, stocks_sold): if self.stock > stocks_sold: self.stock -- stocks_sold 27 28 29 30 else: 31 print(f"Not enough stocks of {self.name} for selling.") 32 33 hopia = Product("Hopia", "food", 4, 100, 20)
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Query Syntax
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education