Exercise 41. Rectangle class: || Solution
- Write a Rectangle class in Python language, allowing you to build a rectangle with length and width attributes.
- Create a Perimeter() method to calculate the perimeter of the rectangle and a Area() method to calculate the area of the rectangle.
- Create a method display() that display the length, width, perimeter and area of an object created using an instantiation on rectangle class.
- Create a Parallelepipede child class inheriting from the Rectangle class and with a height attribute and another Volume() method to calculate the volume of the Parallelepiped.
Exercice 42: Person class and child Student class || Solution
- Create a Python class Person with attributes: name and age of type string.
- Create a display() method that displays the name and age of an object created via the Person class.
- Create a child class Student which inherits from the Person class and which also has a section attribute.
- Create a method displayStudent() that displays the name, age and section of an object created via the Student class.
- Create a student object via an instantiation on the Student class and then test the displayStudent method.
Exercise 43. Bank Account class: || Solution
- Create a Python class called BankAccount which represents a bank account, having as attributes: accountNumber (numeric type), name (name of the account owner as string type), balance.
- Create a constructor with parameters: accountNumber, name, balance.
- Create a Deposit() method which manages the deposit actions.
- Create a Withdrawal() method which manages withdrawals actions.
- Create an bankFees() method to apply the bank fees with a percentage of 5% of the balance account.
- Create a display() method to display account details.
- Give the complete code for the BankAccount class.
Exercise 44. Circle class
1 - Define a Circle class allowing to create a circleC (O, r) with center O(a, b) and radius r using the constructor: def __init__(self,a,b,r):
self.a = a
self.b = b
self.r = r
2 - Define a Area() method of the class which calculates the area of the circle.3 - Define a Perimeter() method of the class which allows you to calculate the perimeter of the circle.
4 - Define a testBelongs() method of the class which allows to test whether a point A(x, y) belongs to the circle C(O, r) or not.
Exercise 45. Computation class:
1 - Create a Coputation class with a default constructor (without parameters) allowing to perform various calculations on integers numbers.2 - Create a method called Factorial() which allows to calculate the factorial of an integer. Test the method by instantiating the class.
3 - Create a method called Sum() allowing to calculate the sum of the first n integers 1 + 2 + 3 + .. + n. Test this method.
4 - Create a method called testPrim() in the Calculation class to test the primality of a given integer. Test this method.
4 - Create a method called testPrims() allowing to test if two numbers are prime between them.
5 - Create a tableMult() method which creates and displays the multiplication table of a given integer. Then create an allTablesMult() method to display all the integer multiplication tables 1, 2, 3, ..., 9.
6 - Create a static listDiv() method that gets all the divisors of a given integer on new list called Ldiv. Create another listDivPrim() method that gets all the prime divisors of a given integer.
Exercise 46
- Define a Book class with the following attributes: Title, Author (Full name), Price.
- Define a constructor used to initialize the attributes of the method with values entered by the user.
- Set the View() method to display information for the current book.
- Write a program to testing the Book class.
Exercise 47
Write a Geometry class with default constructor having no parameters.- Write a methode in Geometry class called distance() that allow to compute a distance between two points A = (a1, a2), B = (b1, b2) (with the convention: a point M is identified with its pair of coordinates M = ( x, y)).
- Write a methode in Geometry class called middle() allowing to determine the midle of bipoint (A,B).
- Write method called trianglePerimeter() allowing to compute the perimeter of triangle
- Write method called triangleIsoscel() which returns a True if the triangle is isoscel and False if not.
Exercise 48
Coding a class named myString inheriting from the str class allowing to endow strings with append() and pop () methods doing the same operations as those of lists class.Exercise 49 || Solution
1- Create a class called TK_extended which inherits from TK class and having the attributes:- Master: that represents the name of the main window
- title: that represents the title of the main window
2 - Create a method called create() that creates the window
3 - Create a method called resize(width, height) that can resize the window.
4 - Create a method called generate() to generate the window
Younes Derfoufi
my-courses.net
my-courses.net
Need answer of exercise 45
ReplyDelete