Social Icons

Saturday, February 29, 2020

Exercise 41 

  1. Write a Rectangle class in Python language, allowing you to build a rectangle with length and width attributes.
  2. Create a Perimeter() method to calculate the perimeter of the rectangle and a Area() method to calculate the area of ​​the rectangle.
  3. Create a method display() that display the length, width, perimeter and area of an object created using an instantiation on rectangle class.
  4. 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.


class Rectangle:
    # define constructor with attributes: length and width 
    def __init__(self, length , width):
        self.length = length
        self.width = width
    # Create Perimeter method
    def Perimeter(self):
        return 2*(self.length + self.width)
    # Create area method
    def Area(self):
        return self.length*self.width   
    # create display method
    def display(self):
        print("The length of rectangle is: ", self.length)
        print("The width of rectangle is: ", self.width)
        print("The perimeter of rectangle is: ", self.Perimeter())
        print("The area of rectangle is: ", self.Area())
class Parallelepipede(Rectangle):
    def __init__(self, length, width , height):
        Rectangle.__init__(self, length, width)
        self.height = height
    # define Volume method
    def volume(self):
        return self.length*self.width*self.height
myRectangle = Rectangle(7 , 5)
myParallelepipede = Parallelepipede(7 , 5 , 2)
print("the volume of myParallelepipede is: " , myParallelepipede.volume())

The output is:
The length of rectangle is:  7
The width of rectangle is:  5
The perimeter of rectangle is:  24
The area of rectangle is:  35
the volume of myParallelepipede is:  70

Younes Derfoufi

Friday, February 28, 2020

Exercise 41. Rectangle class: ||  Solution

  1. Write a Rectangle class in Python language, allowing you to build a rectangle with length and width attributes.
  2. Create a Perimeter() method to calculate the perimeter of the rectangle and a Area() method to calculate the area of ​​the rectangle.
  3. Create a method display() that display the length, width, perimeter and area of an object created using an instantiation on rectangle class.
  4. 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

  1. Create a Python class Person with attributes: name and age of type string.
  2. Create a display() method that displays the name and age of an object created via the Person class.
  3. Create a child class Student  which inherits from the Person class and which also has a section attribute.
  4. Create a method displayStudent() that displays the name, age and section of an object created via the Student class.
  5. Create a student object via an instantiation on the Student class and then test the displayStudent method.

Exercise 43. Bank Account class: ||  Solution

  1. 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.
  2. Create a constructor with parameters: accountNumber, name, balance.
  3. Create a Deposit() method which manages the deposit actions.
  4. Create a Withdrawal() method  which manages withdrawals actions.
  5. Create an bankFees() method to apply the bank fees with a percentage of 5% of the balance account.
  6. Create a display() method to display account details.
  7. Give the complete code for the  BankAccount class.

Exercise 44. Circle class || Solution

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 || Solution

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 Class Book || Solution

  1.  Define a Book class with the following attributes: Title, Author (Full name), Price.
  2. Define a constructor used to initialize the attributes of the method with values entered by the user.
  3. Set the View() method to display information for the current book.
  4. Write a program to testing the Book class.

Exercise 47 Class Geometry || Solution

Write a Geometry class with default constructor having no parameters.
  1. 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)).
  2.  Write a methode in Geometry class called middle() allowing to determine the midle of bipoint (A,B).
  3. Write method called trianglePerimeter() allowing to compute the perimeter of triangle
  4. Write method called triangleIsoscel() which returns a True if the triangle is isoscel and False if not.

Exercise 48 Class String || Solution

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 Class Tkinter Extended|| 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

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"


def swapWord(s):
    # converting the string s to a python list
    L = s.split()
    n = len(L)
    # getting the first and the last word
    first = L[0]
    last = L[n-1]
    # create a substring s1 by deleting the the first and last word
    s1 = " "
    for i in range(1,n-1):
        s1 = s1 + L[i] + " "
    # swapping the first and the last word
    s2 = last + s1 + first
    return s2
s = "Python is a programming language"
print("The string obteined by swaping the the first and the last word is :\n", swapWord(s))

Younes Derfoufi

Thursday, February 27, 2020

Exercice 39

Write a Python program that counts the number of words on a string


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 algorithm
s = "Python is the most popular programming language"
print("The number of words in s is :", countWord(s))
# The output is : 'The number of words in s is : 7'

Younes Derfoufi

Monday, February 24, 2020

 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:

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.

Exercise 38 

Write a Python program to find the longest word on a string.


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 maxWord
# Testing algorithm
s = "Python is object oriented programming language"
print("The longest word in s is : " , longestWord(s))
# This will display : The longest word in s is :  programming

Younes Derfoufi

Thursday, February 20, 2020

Exercise 37

Write a Python program that creates a list whose elements are the common words to two strings s1 and s2.


def commonWords(s1 , s2):
    listCommonWords = []
    # convert s1 and s2 to python lists
    L1 = s1.split()
    L2 = s2.split()
    # browsing the list elements
    for word in L1:
        if( word in L2 and word not in listCommonWords):
    return listCommonWords
# Exemple for testing algorithm 
s1 = "Python is oriented object programming language"
s2 = "Python is a programming language created in 1991"
print("The common words : " , commonWords(s1,s2))
# display : The common words :  ['Python', 'is', 'programming', 'language']

Younes Derfoufi

Wednesday, February 19, 2020


Write a program in Python to delete multiple spaces in a string


# Example of strings containing multiple spaces
s = " Python      is      object oriented a programming     language"
# transform the string s to a python list
L = s.split()
#define an empty string s2
s2 = ""
# reconvert the list L in a chain by browsing the elements of the list.
for element in L:
    s2 = s2 + element + " "
# The chain without multiple space

Younes Derfoufi
The os module is a module provided by Python whose purpose is to interact with the operating system, it thus makes it possible to manage the tree structure of files, to provide information on the operating system processes, system variables, as well as many system features… The os module can be loaded simply with the command: import os

Monday, February 17, 2020

1 - What is a Python module ?

A module in Python is simply a file made up of Python code that you can call and use its code without having to copy it. A module can contain functions, classes, variables ... A module allows you to logically organize your Python code. The grouping of associated code in a module makes the code easier to understand and use.
Stadia has had a difficult start. It is blamed more than compliments and Google is trying to reverse the trend by revealing a list of games and improvements scheduled for the coming weeks.
Five games, three of which exclusive, will be added to the small Google Stadia catalog. Finally ! And this, as the three-month trial period of Stadia Pro, included with the Founders and Premiere offers, is about to end. Would Google have felt that the tide would turn if it did not quickly give some of the names of the ten titles that are only developed for its cloud gaming service?

Sunday, February 16, 2020

1 - Concept of inheritance and parent class

To avoid copying the code of a class, we use the inheritance method. The inheritance method consists in creating from a parent class or (mother class) another class called daughter class or (child class) which inherits all the methods and properties of the mother class. To simplify the acquisition for beginners, we will treat this concept on simple examples:

2 - Examples of inheritance in Python Mother class:

class Person:
      def __init __ (self, name, age):
 = name
          self.age = age
We have just defined a Person class whose attributes are name and age. We are now going to create a child class named Student which inherits the same methods and properties from the Mother person class. The general inheritance syntax is done using the command:
class child_class(parent_class)
Which means that the class classe_child inherits from the called parent_class

3 - Concrete example: Student child class which inherits from the Parent Person class

class Student (Person):
The inheritance of the name and age attributes is done via the command:
Person.__ init __ (self, name, age)
Student child class code:
class Student(Person):
     # definition of attributes
     def __init__ (self, name, age, sector):
          # inheritance of attributes from the parent class Person
          Person.__init__(self, name, age)
          # addition of a new file attribute to the child class
          self.sector = sector
A complet Example:
class Person:
     def __init__(self, name, age):
 = name
          self.age = age
class Student(Person):
     # definition of attributes
     def __init__ (self, name, age, sector):
          # inheritance of attributes from the parent class Person
          Person.__init__(self, name, age)
          # addition of a new file attribute to the child class
          self.sector = sector
exampleStudent = Student("Albert" , 25 , "mathematics")
print("Student name is  : " ,
print("Student age is  : " , exampleStudent.age)
print("Student sector is  : " , exampleStudent.sector)
This will display after execution:
Student name is : Albert 
Student age is : 25 
Student sector is : mathematics

Google’s famous map and route app is getting a complete overhaul in its mobile version on both Android and iOS.
A few days ago, Google celebrated the 15th anniversary of Maps, its famous - and almost unavoidable - cartography and route service, launched on February 8, 2005. For the occasion, the editor of Mountain View unveiled a new logo highlighting the famous pin now in the emblematic colors of the company, while announcing the arrival of a new version of its mobile application, the online version remaining for the time being virtually unchanged.
The good news is that after a drop-by-drop deployment, the new version of the Google Maps application is now available to everyone, in French, on Android and on iOS! To benefit from it, always for free, of course, you just have to update from the Play Store or the App Store.
In addition to the icon change, the new version of the Google Maps application benefits from a complete overhaul, with significant modifications to its interface. Thus, the menu called "hamburger" - the three small horizontal lines at the top - disappears, most of its elements remaining accessible via the avatar icon at the top right.
In return, the items related to navigation are now grouped in five tabs at the bottom of the screen.
- Discover allows you to explore, search and find new places around.
- Routes is used to search for an itinerary taking into account multimodal journeys - that is to say combining several means of transport -, while offering the possibility of using the new Live View mode, which displays directions in augmented reality for pedestrian routes.
- Saved brings together the saved places, but also the reservations, the app fetching them directly in Gmail or in Google Calendar.
- Contribute allows you to add information, publish photos and leave comments on places to improve the community dimension of the application.
- Finally, Actualités displays suggestions for interesting places located near places that are often visited.
Major innovations that will require a little time to adapt, but which prove that Google is keeping up with the times by constantly improving its flagship application. A small change of habits to be expected, therefore, but which is justified, especially since Google Maps now benefits from a private browsing mode, which avoid leaving traces on his travels.

Saturday, February 15, 2020

What is pass instruction ?

The pass statement does nothing. It can be used when an instruction is required to provide correct syntax, but no action should be taken.

Examples of using the pass instruction 

If we want to exclude only minors!
age = int(input("Type youre age :"))
if age > 18:
    print("You are a minor !")
This instruction is commonly used to create minimal classes:
class MyEmptyClass:
If we want to create a class with constructor without parameters:
class MyEmptyClass:
    def __init__(self):

Younes Derfoufi

The Chinese manufacturer is making a nice move upmarket with its new Mi 10 smartphones, direct competitors of the Samsung Galaxy S20.
Xiaomi has decidedly big ambitions. The Chinese manufacturer, which was in fourth position on the global smartphone market in 2019, intends to introduce itself eventually - and, why not, from 2020 - in the top three by dislodging Apple or Huawei, behind Samsung. And while taking advantage of the delicate situation of his compatriot Huawei, still subject to American sanctions, Xiaomi has decided to go on the offensive now by presenting the Mi 10, very high-end models which pose as direct competitors of the Galaxy S20, the brand new flagships of Samsung.

Python Exercises With Solutions

  1. Exercises on Python Strings
  2. Exercises on Python lists
  3. OOP Exercices with solutions
  4. Exercises on Python File I/O
  5. Python Dictionary Exercises
  6. Python Sets Exercises
  1. Python Arithmetic Exercises
  2. Equations & System Of Equations
  3. Polynomials and Functions
  4. Python Arithmetic Exercises 
  5. Numpy, Matplolib, Sympy , Scipy - Exercises
  6. Python Arithmetic Exercises
  1. Python GUI Tkinter Exercises

Younes Derfoufi

Category Of Mobile Courses

Actualités (644) Adsense (1) Affiliation (1) Algebraic Topology (2) Algorithmic (1) all-news (30) Android (5) Android App (8) Android app without code (4) Android Apps (256) Android Development (4) Android download (2) Android OS (3) AngularJS (1) Automata theory and formal language (5) Bootstrap CSS (1) C programming (5) Category and Functor (8) CMS (3) Computer Glossary (18) Create Mobile App With Ionic Framework (2) CSS (2) CSS-Cascading-Style-Sheets (4) Developpement Java (13) Differential Geometry (1) Django-Python-Framework (9) dropshiping (26) Earn Money by Internet (4) Emplois (23) Framework php (2) Fraud (2) HTML (7) Java For Beginners (10) Javascript (12) Kotlin Programming Language (8) Kotlin For Mobile Android (1) Linux Download (2) Marketing (5) Mobile (3) Mobile Courses (4) Mobile Marketing (4) MoneyGram (1) News (721) Node.js (5) Open Source (1) Photoshop (1) Protect Computer (1) Python (35) Python BeautifulSoup (1) Python For Data Science (2) Python PyQt (4) Python Reference (1) Python Source Code (1) Python-Books (6) Python-DVD-Training (1) Python-Exercises (297) Python-Framework (1) Python-IDE (1) Python-Kivy-Framework (2) Python-Modules (1) Python-pdf (2) Python-pyQt (1) Référencement (2) Script PHP (2) Security (6) SEO (1) Snipping Tool: Faq (1) Social Networks (1) Source Code (4) Statistics With SPSS (2) Surveillance Software (1) Travail à domicile (6) Tutoriels php en vidéos (2) Tutoriels-MySql (6) tutoriels-php (19) Utilitaires (1) VPS (1) Web Hosting (1) Webcam (1) Webmarketing (11) Western Union (1) Windows 10 (1) Windows 7 (4) Windows 7 Faq (2) Windows 8 (1) Windows Accessories (1) Windows Download (8) Windows Drivers (1) Windows Fonts (1) Windows Power Shell (2) Windows Registry (2) Windows Security (18) Windows Software (2) Windows Spyware (2) Windows utilities (3) Windows Virus (2) Windows Vista (3) Windows Wireless (1) Windows xp (1) Wordpress (1)

Sample text

Sample Text

Blogger Templates