Question: In Python Create a class named Spam in a file named spam.py . You must attach your spam.py file to this question by using the
In Python
Create a class named Spam in a file named spam.py. You must attach your spam.py file to this question by using the file upload form below.
Give the Spam class these properties:
An __init__() method that has "name" and "cost" parameters.
A name() method stores the name of the Spam instance.
A get_name() method that returns the instance's name.
A cost() method that stores the item's cost.
A get_cost() method that returns the item's cost.
A class variable named total_cost that contains the total cost of all existing items. Update this variable each time a new Spam instance is created.
A class method named get_total_cost() that returns total_cost.
A class variable named items_count that keeps track of the objects created. Update this variable each time a new Spam instance is created.
A class method named get_items_count() that returns items_count.
Create a _main() function that is executed when the spam.py code is run as a standalone script, like this on the command line: ./spam.py
All of these are gradable items.
In addition, write and run test code that
Creates at least three Spam objects.
Prints the output of the get_total_cost() and get_items_count() class methods each time an new spam object is created.
Prints the output of the get_name() and get_cost) for all three Spam objects.
Include the output in your answer.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
