Social Icons

Saturday, September 18, 2021

Exercise 93 *

Write an algorithm in python which transforms a list of integers L = [n1, n2, n3, ...., np] into the list of factorials: [n1! , n2! , n3!, ...., np!]

Solution

Friday, September 17, 2021

Exercise 92**

Write a python algorithm which transforms a list of integers
L = [n1, n2, n3, ...., np]
into a list whose elements are the averages of the partial sums:
[n1, average(n1, n2) , average(n1, n2, n3), ...., average(n1, n2, ..., np)]

Solution

Thursday, September 16, 2021

Exercise 91 **

Write an algorithm in python as a function that transforms a string text T into a list where words containing numbers are placed at the end of the list. Example if T = "Python_1 created in 1991. Currently it is in version Python_3.9" the algorithm returns the list: ['created', 'in', 'Currently', 'it', 'is', 'in', 'version', 'Python_1', '1991.', 'Python_3.9' ]

Solution

Wednesday, September 15, 2021

Exercise 97 *

Write a python algorithm as a function which takes as parameter a couple (s, x) formed by a text string s and a char x and which returns the index of the second position of the character x in the string s without using no predefined function. The function should return -1 if the char x is not in the string s. Example if s = 'python programming language' and x = 'p', the function returns the index: 7

Solution

Tuesday, September 14, 2021

Exercise 96 *

Write an algorithm in Python as a function which takes a text string as parameter and which returns the list of words containing at least two uppercase letters. Example if
 s = 'The PySide GUI library is more popular than PyQt'
, the function returns the list:
['GUI', 'PySide', 'PyQt']

Solution

Monday, September 13, 2021

Exercise 90 *

Given a list of integers
L = [n1, n2, n3, ..., np]
, write an algorithm in python which returns the list:
L_sum = [n1, n1 + n2, n1 + n2 + n3, .. ., n1 + n2 + n3 + ... + np]

Solution

# function which calculates the sum of the list elements
def sumList (L):
    # initialization of the sum of the list elements 
    s = 0
    for x in L:
        s = s + x
    return s

# function which determines the list L_sum
def sum_list (L):
    # initializationh of the list L_sum
    L_sum = []
    for i in range (0, len (L)):
        L_sum.append (sumList (L [0: i+1]))

    return L_sum

# Example
L = [3, 2, 5, 1, 0, 7]
print ("L_sum =", sum_list (L))


Younes Derfoufi
my-courses.net

Sunday, September 12, 2021

Exercise 89 *

Given a list L, write a python algorithm which returns the list of digits contained within the elements of list L without repetition. Example if L = ["Python3", 91, "Java2", 95], the algorithm returns the list [3, 9, 1, 2, 5]

Solution

Saturday, September 11, 2021

Exercise 88 *

Given a list L, write a python algorithm which returns the list of digits contained within the elements of the list L. Example if L = ["Python3", 91, "Java2", 95], the algorithm returns the list [3, 9, 1, 2, 9, 5]

Solution

Friday, September 10, 2021

Exercise 87

Given a list L, write a Python algorithm to convert a list into a string without using any predefined method other than the str() method. Example if L = ["Python", "created on", 91, "by Guido Van Rosam"], the algorithm returns the string s = "Python created on 91 by Guido Van Rosam".

Solution

Exercise 86

Given a list L, write a python algorithm which returns the list of integer elements of L. Example: if
 L = ["Python3", 91, "Java2", 95]
, the algorithm returns the list
[91, 95]

Solution

Thursday, September 9, 2021

Exercise 85

Write a python program which that move the null values of a list to the end of the list while keeping the order of the other non-null elements. Example if the list is: L = [7, 0, 11, 5, 0, 21, 0, 2, 0, 0, 9] the output is: [7, 11, 5, 21, 2, 9, 0, 0, 0, 0, 0]

Solution

Wednesday, September 8, 2021

Exercise 84

96 is an integer whose tens digit is divisible by 3 (property (*)) Given an integer n, write an algorithm in python which returns the list of integers less than or equal to n composed of two digits and checking the property (*)

Solution

Exercise 83

Write a python algorithm which replaces the elements of even index by 2 and the elements of odd index by 1.

Solution

Solution

# function which replaces the elements of even index by 2 and the elements of odd index by 1
def replace (L):

    # initialization of the searched list
    list_2_1 = []

    for i in range (0, len (L)):
        if i% 2 == 0:
            list_2_1.append (2)
        else:
            list_2_1.append (1)
    return list_2_1

# Example
L = ["Python", "Java", "C ++", "C #", "Javascript"]
print (replace (L)) # print: [2, 1, 2, 1, 2]


Younes Derfoufi
my-courses.net

Tuesday, September 7, 2021

Exercise 82

Write a program in Python which determines the list of words containing two successive identical characters in a character string s. Example if s = "Python is the most recommended programming language", the algorithm returns the list
 ["recommended", "programming"].

Solution

Monday, September 6, 2021

Exercise 79

Write using the count() method, a python algorithm as a function which takes as parameter a list of integers L and which returns without repetitions the list of tuples (n, occ_n) formed by the elements n of L and their occurrence occ_n. Example: if
L = [22, 7, 14, 22, 7, 14, 7, 14, 11, 7],
the algorithm returns the list
[(22, 2), (7, 4), (14, 3 ), (22, 1), (11, 1)]

Solution

Exercise 78

Given a list made up of the students' averages avg_list, write a python algorithm that determines the first index of the average which is less than 10. Example if
avg_list = [12, 17, 10, 7, 11, 14, 15, 9]
, the algorithm returns index 3.

Solution

Exercise 77

Repeat the previous exercise (Exercise 76) without using the max() method.

Solution

Exercise 76

Write a Python algorithm that determines the first index of the maximum in a given list using the max () method. Example if
L = [22, 7, 88, 41, 14, 88, 9]
, the algorithm returns the first index of the maximum which is 2.

Solution

Exercise 75

Write a Python algorithm to reverse a list without using the reverse() method

Solution

Sunday, September 5, 2021

Exercise 74

Write a Python algorithm that asks the user to enter successively 7 integers and display the list of numbers entered by ignoring repeated numbers. Example if the user enters the numbers: 2, 11, 3, 2, 3, 5, 2. the algorithm returns the list
[2, 11, 3, 5]

Solution

Exercise 73

Write a function which takes as parameter a variable of type string s and another string T, and returns the list of positions of a pattern s in the string T. The function must return the empty list if the pattern s does not appear in the text T.

Solution

Exercise 46

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.

Solution

Saturday, September 4, 2021

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.

Solution

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.

Solution

Exercise 72

Write a function which takes an element x and a list L as a parameter, and returns the list of positions of x in L. The function must return the empty list if the element x does not appear in the list L.

Solution

Exercise 71

Write a Python algorithm that transforms a list of integers L = [n1, n2, n3, ..., np] by adding 1 to the first element, 2 to the second element, 3 to the third element, ..., p to the pth element. The algorithm must return at the end the list
[n1 + 1, n2 + 2, n3 + 3, ..., np + p]
.

Solution

Friday, September 3, 2021

Exercise 70

Write a Python algorithm to test if a given list is symmetric using the reverse() method. Example: for L1 = [2, 5, 11, 5, 2] the algorithm returns True and for L2 = [2, 23, 11, 51, 7] the algorithm returns False.

Solution

Exercise 69

Write a Python algorithm which determines for a given integer n the list of tuples of integers (p, q) satisfying:
p2 + q2 = n

Solution

Thursday, September 2, 2021

Exercise 68

Write a Python algorithm which determines for a given integer, the list of perfect squares between 1 and n. Example if n = 100 the algorithm returns the list
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

Solution

Exercise 67

Write without using any predefined function a Python algorithm as a function which takes as parameter a list of integers L and which returns True if the list is arranged in ascending order and False if not.

Solution



Exercise 66

Write a Python algorithm to extract the list of integers from a list of numbers. Example: if
L = [2.5 , 11.54 , 3 , 7.35 , 5 , 6.5 , 9]
, the algorithm returns the list
[3, 5, 9]

Solution



Exercise 65

Given a list of strings, write a Python algorithm allowing which replace the elements of the list with their lengths. Example: if
 L = ["Python", "Django", "Numpy", "Sympy"]
, the algorithm returns the list
[6, 6, 5, 5]

Solution

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 (295) 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