In: Computer Science
Write a python source code for a Unit class corresponding to the UML model of a Unit shown. The description method should return a string value corresponding to the attributes of a Movie.
Unit |
-code: String -name: String -credit points: int |
+ __init__ (self, code, name, credit_points) + description (): String |
In case of any query, do comment. Please rate answer. Thanks
Code:
#class Unit
class Unit:
#data member
code=""
name=""
credit_points=0
#constructor
def __init__(self,code,name,credit_points):
self.name = name
self.code = code
self.credit_points = credit_points
#description method
def description(self):
return "Code : {} , Name: {} , Credit Points: {}".format(self.code,self.name,self.credit_points)
#main program to create object
unit1 = Unit("123","unit1",4)
#print the description
print(unit1.description())
Screen shot of code and output: