The steelwork.py program, given below, creates three types of steel objects. Carbon steel (Steel) is made of carbon and iron, alloy steel (AlloySteel) contains chromium in addition to carbon and iron. Stainless steel (StainlessSteel) contains nickel and a higher proportion of chromium.  Write the missing code, in the designated locations (#TODO), in order for the program execution to yield the following output:   ['Steel01', 0.6, 91] ['ALSteel02', 0.6, 91, 1] ['SSteel02', 0.6, 91, 11, 2]

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
Question

The steelwork.py program, given below, creates three types of steel objects. Carbon steel (Steel) is made of carbon and iron, alloy steel (AlloySteel) contains chromium in addition to carbon and iron. Stainless steel (StainlessSteel) contains nickel and a higher proportion of chromium.  Write the missing code, in the designated locations (#TODO), in order for the program execution to yield the following output:

 

['Steel01', 0.6, 91]

['ALSteel02', 0.6, 91, 1]

['SSteel02', 0.6, 91, 11, 2]

# steelwork .py
A# Author : Youcef Derbal
2
el class Steel:
def -_init__(self,*args, **kwargs):
# TODO Complete code for the __init__ method
6
7
def tostring(self):
8
return [self.code, self.carbon,self.iron]
10
@classmethod
11
def factory(cls,*args):
n = len(args)
if n == 3:
12
13
14
return Steel(*args)
15
elif n == 4:
16
return Alloysteel(*args)
17
elif n == 5:
18
return StainlessSteel(*args)
19
el class Alloysteel(Steel):
20
21
# TODO Add code for the -_init__ method
22
23 l of
def tostring(self):
return super(Alloysteel, self).tostring()+ [self.chromium]
24
25
26
eclass StainlessSteel(AlloySteel):
27
# TODO Add code for the _init__ method
28
29
of a
def tostring(self):
return super(StainlessSteel, self).tostring()+ [self.nickel]
30
31
s1 = Steel.factory('Steel01',0.6,91)
s2 = Steel.factory(1, 'ALSteel02',0.6,91)
s3 = Steel.factory(2,11,'SSteel02',0.6,91)
32
33
34
35
36
print(s1.tostring())
37
print(s2.tostring())
38
print(s3.tostring())
Transcribed Image Text:# steelwork .py A# Author : Youcef Derbal 2 el class Steel: def -_init__(self,*args, **kwargs): # TODO Complete code for the __init__ method 6 7 def tostring(self): 8 return [self.code, self.carbon,self.iron] 10 @classmethod 11 def factory(cls,*args): n = len(args) if n == 3: 12 13 14 return Steel(*args) 15 elif n == 4: 16 return Alloysteel(*args) 17 elif n == 5: 18 return StainlessSteel(*args) 19 el class Alloysteel(Steel): 20 21 # TODO Add code for the -_init__ method 22 23 l of def tostring(self): return super(Alloysteel, self).tostring()+ [self.chromium] 24 25 26 eclass StainlessSteel(AlloySteel): 27 # TODO Add code for the _init__ method 28 29 of a def tostring(self): return super(StainlessSteel, self).tostring()+ [self.nickel] 30 31 s1 = Steel.factory('Steel01',0.6,91) s2 = Steel.factory(1, 'ALSteel02',0.6,91) s3 = Steel.factory(2,11,'SSteel02',0.6,91) 32 33 34 35 36 print(s1.tostring()) 37 print(s2.tostring()) 38 print(s3.tostring())
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
File Input and Output Operations
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
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