## Solution Exercise 41 - Rectangle class and inherited child Parallelepipede class

Exercise 41  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…

## Exercises with solutions on OOP - object oriented programming in Python

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,…

## Solution Exercise 40: Python program to swap the first and the last word in a string

Exercise 40  Write a Python program that allows you to swap the first and the last word. Example if s = "Python is a programming language", the program returns the string s2 = "programming is a Python language" Solution: def swapWord(s): # converting the string s to a python list L = s.split() n =…

## Solution Exercice 39 : the number of words in python string

Exercice 39 Write a Python program that counts the number of words on a string Solution def countWord(s): # convert the string s to a list L = s.split() # The number of words in a string s is exactly equal to the len of the list L return len(L)# Testing algorithms = "Python is…

## The Python NumPy Library

1.  About numpy  1.1 What is numpy ? Numpy is an open source library associated with the Python language, created specially for scientific computing, notably matrix computing, while providing multiple functions allowing the direct creation and manipulation of matrices, vectors, etc... via data. Official documentation: https://numpy.org/doc/ 1.2 How to install numpy ? Installing the numpy…

## Python Matplotlib module

1. About matplotlib module The matplotlib module is a large and very complete module. Here we are going to look at some examples of use such as for example the plotting of graphical representations of functions or statistical series. More information on official documentation can be found here. 2. Importing the matplotlib & pyplot module. …

## Solution Exercise 38: algorithm python to find the longest word

Exercise 38  Write a Python program to find the longest word on a string. Solution: def longestWord(s): # Converting the string s to a list L = s.split() # define temporary longest word maxWord = "" # Browsing all items in list L for word in L: if (len(maxWord) < len(word)): maxWord = word return…