Python 3 help..dunno where to start. The objective of this lab is to give you so
ID: 3593629 • Letter: P
Question
Python 3 help..dunno where to start.
The objective of this lab is to give you some experience working w The object container, to a global ve you some experience working with Digital Versatile Disc (DVD) om a user-defined DVD class and passing DVD objects to functions that manipulate tc s you will model in this lab will be software DVDs. You will create several DVD objects and d information into their instance variables. All of these DVD objects will then be passed, in a list it receives. The list of DVD objects will then be passed to another global function that computes and displays the total costs as well as the average cost for the DVDs it receives. Finally, a function that receives a single DVD object will be called twice-once for each of the first two of the individual DVD objects. This function will allow the user to interactively change selected data items in the single DVID object passed to this function. This lab represents a hybrid solution which incorporates both objects of a Python class as well as global, free-standing, C-like functions that process objects) passed to them. Hybrid solutions such as this are actually modeled as obiects! the most common solutions found in practice si nce the world typically cannot be ENTIRELY Specifications (minimum): The DVD class contains the following instance variables self. Title self. DVDType; self. Cost # The Name of the DVD # The Type of DVD # The Cost of the DVD The ONLY recognized (i.e., legal) software DVD types are, "Game", "Word", "Compiler", "Spreadshee “Dbase", and "Presentation" (AND, no others). The DVD class contains (at a minimum) the following methods: init (self, InTitle, InDVDType, InCost): . . . # Constructor-initialize instance variables # with (validated) parameter values # Change the self.--Title instance variable value # Return self.--Title instance variable value setTitle(selfNewTitle): getTitle(self): .. setType(self NewType). . . . getType(self):.. setCost(self, NewCost): getCost(self):... litValidDVDtypes(self) loadInformation(self): # Validate & change the self: DVD-Type instance variable valu # Return self.--DVD-Type instance variable value # Return the value in the self-Cost instance variable value #Support method that display list of valid DVD types # Interactively prompt-for, input, and set all instance variables The global functions are as follows: 10(10/2017 8:24Explanation / Answer
def displayDVDinformation(dvds):
for obj in dvds:
print(obj.title)
print(obj.dvd_type)
print(obj.cost)
def displayTotalAndAverageCost(dvds):
add=0
for obj in dvds:
add+=obj.cost
print(obj.cost)
avg=add/len(dvds)
print('Average cost: ',avg)
def changeDVD(dvd):
print('DVD title is ',dvd.title)
in1=input('Want to change title (y/n): ')
if in1 in ['y','Y']:
title=input('Enter title: ')
dvd.title=title
else:
pass
print('DVD type is ',dvd.dvd_type)
in2=input('Want to change type (y/n): ')
if in2 in ['y','Y']:
validType=['Game','Word','Compiler','Spreadsheet','Dbase','Presentation']
while True:
dvd_type=input('Enter valid type: ')
if dvd_type.title() not in validType:
continue
else:
dvd.dvd_type=dvd_type
break
else:
pass
print('DVD cost is ',dvd.cost)
in3=input('Want to change cost (y/n): ')
if in3 in ['y','Y']:
cost=int(input('Enter cost: '))
dvd.cost=cost
else:
pass
class DVD(object):
def __init__(self,title,dvd_type,cost):
self.title=title
self.dvd_type=dvd_type
self.cost=cost
def setTitle(self,newTitle):
self.title=newTitle
def getTitle(self):
return self.title
def setType(self,newType):
self.dvd_type=newType
def getType(self):
return self.type
def setCost(self,newCost):
self.cost=newCost
def getCost(self):
return self.cost
def listValidDVDtypes(self):
validType=['Game','Word','Compiler','Spreadsheet','Dbase','Presentation']
if self.dvd_type.title() in validType:
return True
else:
return False
def loadInformation(self):
title=input('Enter DVD title: ')
self.setTitle(title)
dvd_type=input('Enter DVD type: ')
self.setType(dvd_type)
cost=int(input('Enter DVD cost: '))
self.setCost(cost)
def main():
list1=[]
dvd1=DVD('abc','xyz',100)
dvd2=DVD('abc','xyz',100)
dvd3=DVD('abc','xyz',100)
dvd1.loadInformation()
list1.append(dvd1)
dvd2.loadInformation()
list1.append(dvd2)
dvd3.loadInformation()
list1.append(dvd3)
print('ALL DVD INFORMATION')
displayDVDinformation(list1)
print('ALL DVD COST')
displayTotalAndAverageCost(list1)
for i in range(2):
changeDVD(list1[i])
print('UPDATED INFORMATION')
displayDVDinformation(list1[0:2])
print('UPDATED COST')
displayTotalAndAverageCost(list1)
if __name__=='__main__':
main()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.