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 …
Create a class Student with two class attributes: school = “Keren Secondary School” and count = 0. In __init__(self, name): store the name, increase Student.count by 1, give the student self.id_number equal to the new count (so the first student …
Finish the BankAccount class: Add a class attribute currency = “Nakfa”. Give __init__ a second parameter balance with a default value of 0, and store it as self.balance. The code at the bottom creates two accounts and prints them. Expected …
Create a class Student with __init__(self, name, mark) and a __str__ that returns Name: mark, for example Selam: 88. Create a list called students with three objects: Selam (88), Merhawi (72) and Abel (65), in that order. Abel did extra …
Create a class called Book with: __init__(self, title, author, year) that stores all three values. __str__ that returns the text Title (Year) by Author. Create book1 = Book(“Python Basics”, “Selam”, 2024) and book2 = Book(“Eritrean Stories”, “Abel”, 2019), then print …
