Create a class BankAccount. BankAccount(owner, balance=0) stores owner and balance as attributes. deposit(amount) adds amount to the balance. If amount is 0 or less, raise ValueError. withdraw(amount) subtracts amount. If amount is more than the balance, raise ValueError and leave …
A palindrome reads the same forwards and backwards, like “level”. Write a function is_palindrome(text) that returns True or False. Ignore upper and lower case: “Anna” is a palindrome. Ignore spaces: “never odd or even” is a palindrome.
Write a function count_words(text) that returns a dictionary. Each key is a word and each value is how many times the word appears. Ignore upper and lower case: “Tea” and “tea” are the same word. Keys are lowercase. Remove these …
The list scores holds test results for a class in Keren. Create a list passed with every score that is 50 or more, in the same order. Create average: the average of all scores, rounded to 1 decimal place with …
Write a function grade(score) that returns a letter grade as a string: Score Grade 90 to 100 “A” 80 to 89 “B” 70 to 79 “C” 60 to 69 “D” 0 to 59 “F” If the score is below 0 …
Abel buys some items at a market in Asmara. Write a program that works out his bill. Create total: the sum of bread, milk and coffee. If total is more than 100, Abel gets 10% off: create discount equal to …
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() …
