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.

Solution

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)
myRectangle.display()
print("----------------------------------")
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
my-courses.net

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.

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 = 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
my-courses.net

Thursday, February 27, 2020

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 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
my-courses.net

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: https://numpy.org/doc/

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.

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 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
my-courses.net

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.

Solution


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):
            listCommonWords.append(word)
    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
my-courses.net

Wednesday, February 19, 2020

Exercice36 

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

Solution:

# 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
print(s2)


Younes Derfoufi
my-courses.net
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):
          self.name = 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):
          self.name = 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  : " , exampleStudent.name)
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 
 
my-courses.net

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.

my-courses.net

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:
    pass
else:
    print("You are a minor !")
This instruction is commonly used to create minimal classes:
class MyEmptyClass:
    pass
If we want to create a class with constructor without parameters:
class MyEmptyClass:
    def __init__(self):
        pass

Younes Derfoufi
my-courses.net


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.

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) 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-Books (6) Python-DVD-Training (1) Python-Exercises (213) 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 (1) 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