Question
All The code for the exercise needs to be written in python programming language Exercise 1 Create a class ShoppingBasket that has the attributes (customer_id,
All The code for the exercise needs to be written in python programming language
Exercise 1
Create a class ShoppingBasket that has the attributes (customer_id, products). Products is a list of instances from your class Product in exercise 1. Implement the sequence protocol so that your class ShoppingBasket becomes iterable (based on the products list) and implement a dunder method so that you can call len() on your class ShoppingBasket. The result of the methods should be based on the number of products in your shopping basket. Write test code to test both methods.
Exercise 2
Implement an example for Polymorphism. Assume you have an abstract class Vehicle that provides the structure for the methods accelerate() and brake(). Declare two child classes Motorcycle and Bus that inherit from Vehicle. Implement the methods and write some test code. The methods should return a string that indicates in which class the method has been called.
Exercise 3
Inheritance - Create a class Person that takes the firstname, lastname and age as parameters in the initialisation. Add a method to the Person class that prints the name and age of the person. Create a class Student that inherits from Person. Create an instance of Student with the parameters required by the parent class and test if the method to print name and age that is implemented in the parent class is executed as expected. The mechanism to implement this is inheritance
Exercise 04
Implement a Product class with the following attributes (price, product_name, brand). Create a custom string representation for your product class by using the dunder methods __str__ and __repr__. Keep the goals for these methods in mind __str__ is targeted at end users and is about readability while the focus of __repr__ is to provide an unambiguous representation that can be used for debugging and development. Both methods should show the value of all attributes of the instance. Write test code for both methods.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started