## Thursday, September 30, 2021

#### Exercice 61

Write a program in Python that asks the user to enter five integers of their choice and return them a dictionary whose keys are the entered numbers and whose values are the lists of the divisors of the entered numbers. Example if the user enters the numbers: 14, 7, 8, 6, 13 the program returns the dictionary:
``d = {14: [1, 2, 7, 14], 7: [1,7], 8: [1, 2, 4, 8], 6: [1,3,6], 13: [1, 13]}``

## Monday, September 27, 2021

#### Exercise 94 *

Write a Python algorithm which extract from a string text the list of words whose first character is identical to the last. Example if s = "radar number 212", the algorithm returns the list ['radar', '212']

## 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!]

## 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)]``

## 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' ]

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

## 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']``

## 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]

## 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]

## 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".

#### 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]``

## 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]

## 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 (*)

#### Exercise 83

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

#### 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"].``

## 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)]``

#### 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.

#### Exercise 77

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

#### 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.

#### Exercise 75

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

## 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]``

#### 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.

#### 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.

## 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.

#### 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 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.

#### 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]``
.

## 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.

#### 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``

## 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]``

#### 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.

#### 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]``

#### 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]``