Question: Define a class named ShoppingItem which represents a shopping item in the shopping system. The ShoppingItem class contains the following: A data field named code
Define a class named ShoppingItem which represents a shopping item in the shopping system. The ShoppingItem class contains the following:
- A data field named code that defines the code of a shopping item.
- A data field named description that defines the descripton of a shopping item.
- A data field named price that defines the price of a shopping item. The default value is 1.0. The type of the variable price must be a float.
- A data field named quantity that defines the quantity of a shopping item. The default value is 1.
- A constructor/initializer that takes a code, a description, a price and a quantity as parameters and creates a shopping item object.
Keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks.
For example:
| Test | Result |
|---|---|
item = ShoppingItem(11,'Coca Cola Soft Drink 500ml',4,2) print(item.code, item.description, item.price, item.quantity) print(type(item.code)) print(type(item.description)) print(type(item.price)) print(type(item.quantity)) item2 = ShoppingItem(11,'Coca Cola Soft Drink 500ml') print(item2.code, item2.description, item2.price, item2.quantity) | 11 Coca Cola Soft Drink 500ml 4.0 2 |
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
