Create a class Basket: __init__(self, owner) stores the owner and an empty list self.items. add(name, price) adds the tuple (name, price) to self.items. total() returns the sum of all prices. __len__ returns the number of items. __add__(other) returns a new …
The Square class is ready. Add two more classes that also have an area() method that returns the area: Rectangle(width, height) — width × height Circle(radius) — 3.14 * radius * radius The loop at the bottom prints every shape. …
Create a class Employee with __init__(self, name, salary) and two methods: monthly_pay() returns the salary. describe() returns name earns X Nakfa, where X comes from self.monthly_pay(). Create a child class Manager(Employee) with an extra bonus. It overrides monthly_pay() to return …
The Vehicle class is ready. Create a child class Taxi: __init__(self, brand, year, city) calls super().__init__(brand, year) and stores self.city. A new method route() that returns brand taxi in city, for example Fiat taxi in Asmara. Do not write info() …
Create an abstract class Animal: __init__(self, name) stores the name. An abstract method sound(self). A normal method speak(self) that returns name says sound, using self.sound(). Then create two child classes, Dog (its sound() returns “Woof”) and Cat (returns “Meow”). Do …
Make Shape an abstract class with an abstract method area(self). Then give Rectangle its own area() method that returns width × height. The code at the bottom is ready. Expected output: Area: 20
Create a class ShopItem: __init__(self, name, price) stores the name and sets self.price = price (this must go through the setter). A price property that returns the private self.__price. A price setter that saves the new value only if it …
Create a class BankAccount that keeps its money in a private attribute __balance: __init__(self, owner, balance=0) stores self.owner and self.__balance. deposit(amount) adds the amount only if it is greater than 0. withdraw(amount) subtracts the amount if there is enough money; …
Build a BankAccount class with __init__(self, owner, balance=0) and three methods: deposit(amount) — adds the amount to the balance. withdraw(amount) — if the balance is big enough, subtracts the amount and returns True; otherwise changes nothing and returns False. transfer(other, …
Add a method grade(self) to the Student class. It must return a letter based on self.mark: Mark Grade 90 or more “A” 75 to 89 “B” 50 to 74 “C” below 50 “F” The code at the bottom prints each …
