## Wednesday, September 11, 2019

#### Exercise 1

Write an algorithm in python which exchanges two integers m and n entered on the keyboard and which displays the values of the numbers before and after the exchange operation.

#### Solution

``````# Ask user to type values of n and m
n = int(input("Type value of the integer n : "))
m = int(input("Type value of the integer m : "))

# use an auxiliary variable in order to be able to exchange the values of m and n
print("display m and n before exchange values : " , " n = ", n , "m = ", m)
v = 0
v = n
n = m
m = v
print("display m and n after exchange values : " , " n = ", n , "m = ", m)
``````

Younes Derfoufi
my-courses.net

## Friday, September 6, 2019

Exercise 35
Write a program in Python that allows you to transform a given url address into a link.

#### Solution

``````# Ask user to type an url
url = input("Type an url :")
# Ask user to type a text of url link
text_lien = input("Type a text of link")
# convert the url text to a link
url = " " + text_lien + ""
print("The text with link is : ", url)
"""
Example
Type an url :https://www.my-courses.net
Type a text of link My Courses
The text with link is :  < a href="https://www.my-courses.net/" > My Courses< / a >
"""
``````

Younes Derfoufi

#### Exercise 34

Given the list of student notes: notes = [12, 04, 14, 11, 18, 13, 07, 10, 05, 09, 15, 08, 14, 16]. Write a Python program that allows you to extract from this list another list that contains only the notes above the average ( notes > = 10 ).

#### Solution

``````notes = [12, 4, 14, 11, 18, 13, 7, 10, 5, 9, 15, 8, 14, 16]

# define list that will contains the notes above the averge
above = []
for x in notes:
if( x >= 10):
above.append(x)
print("The list that contains only the notes above the average is : ", above)

``````

Younes Derfoufi

#### Exercise 33

Write a program in Python that asks the user to enter a string and display the characters of even index. Example for the string s = "Python", the program returns "Pto".

#### Solution

``````# Ask user to type a string s
s = input("type a string s :")

# define and initialize the string that will contain the characters of even index
even = ""

# search through the string s all characters of even index
for i in range(0,len(s)):
if(i%2 == 0):
even = even + s[i]

print("The extracted string that contains the characters of even index is :", even)
``````

my-courses.net
Unveiled a little less than a year ago, the Microsoft cloud gaming service will be tested in October in 5G in South Korea thanks to an exclusive partnership with the operator SK Telecom.
The cloud gaming offer announced in October 2018 by Microsoft is taking shape. The US company announced on September 4, 2019 the launch of its Project xCloud in South Korea. Microsoft is partnering with South Korean operator SK Telecom for the occasion through an exclusive partnership. The main innovative feature of this agreement is that the service will be available via a 5G connection. The two companies, which spoke at a press conference in Seoul, "will cooperate to unveil the xCloud project in October".

## Thursday, September 5, 2019

#### Exercise 32

Write a program in Python that returns all the lists obtained by swapping the terms of a given list.

#### Solution

``````"""import itertools module :
This module implements many iterator bricks inspired by APL, Haskell and SML constructs.
"""
import itertools
# Example of use
l = [1,2,3,4,5]
permutations = itertools.permutations(l)
L = list(permutations)
print("All lists obtained by swapping the terms of list l :  " , L)
``````

Younes Derfoufi

#### Exercise 31

Write a Python program that retrieves the list of even integers and the list of odd integers from a list of numbers.

#### Solution

``````# 1) define the function that retrieves the list of enven integers
def evenIntegers(l):
# define the list of even integer
even = []

# Browse the evens integers in the list l
for n in l:
if(n%2 == 0):
even.append(n)
return even

# 1) define the function that retrieves the list of odd integers
def oddIntegers(l):
# define the list of even integer
odd = []

# Browse the odd integers  in the list l
for n in l:
if(n%2 != 0):
odd.append(n)
return odd

# Example
l = [4 , 3 , 5 , 18 , 13 , 23 , 48]
print("The list of evens integers is : ", evenIntegers(l))
print("The list of odd integers is : ", oddIntegers(l))
``````

Younes Derfoufi
A mechanism called "Push Pages" would create a unique identifier for each user. It would then be shared with the Authorized Buyers advertising auction customers.
Brave just planted a few more fangs in Google's calves. In September 2018, its legal director Johnny Ryan and two other people filed a complaint against the computer giant for non-compliance with the RGPD. They felt that its online auction system for advertising placement (DoubleClick / Authorized Buyers) has the effect of collecting personal data from users and dispersing them to client advertising agencies, without the user being informed. .

## Wednesday, September 4, 2019

#### Exercise 30

Write a function in Python that allows to compare two lists and to tell us if these two lists have a common value or not.

#### Solution

``````# define a function that compare two lists l1 and l2
def commonElements(l1,l2):
counter = 0
# try if there exists a common element and then increment the counter
for x in l1:
for y in l2:
if(x == y):
counter = counter + 1
if counter >=1:
return True
else:
return False

# Example
l1 = [3, 9, 4, 7]
l2 = [1, 14, 3, 7, 5]
print(commonElements(l1,l2))
``````

Younes Derfoufi

#### Exercise 29

Write a Python program that removes duplicate items from a list.

### First method

``````# -*- coding: utf-8 -*-
# define a function that remove duplicate element in list
def removeDuplicate(l):
# define and initialize list with no duplicate element
unique = []
# building a list with no duplicate element
for x in l:
if x not in unique:
unique.append(x)
return unique

# Example
l = [2, 7, 13, 2, 17, 13, 2, 7, 13]
print(removeDuplicate(l))``````

### Second method

``````
# -*- coding: utf-8 -*-
# define a function that remove duplicate element in list
def removeDuplicate(l):
# convert the list l to a set
SET = set(l)
# reconvert the set SET to a list
L   = list(SET)
return L

# Example
l = [2, 7,7, 13, 2, 17, 17, 13, 15, 15, 2, 7, 13]
print(removeDuplicate(l))
``````

Younes Derfoufi
Without being the update of the decade, Android 10 brings a few new welcome to our smartphones. Pixels are entitled to it today.
It is the regime that Google launches the new version of Android. For the first time in 10 years, the company is renouncing the names of sweets in favor of more conventional version numbers. So do not call it Android Q ... but Android 10. This update is already available on smartphones Pixel and will arrive little by little at other manufacturers. We know for example that Essential, Nokia and OnePlus should be among the first served.

## Tuesday, September 3, 2019

#### Exercise 28

Write a Python program that tests whether a list is empty or not. Same question for a string of characters.

### First method

Try if a list is empty
``````# define a list L
L = list()

# try if the list L is empty
if L == []:
print("The list  L is empty")
else:
print("The list L is not  empty")
``````
Try if a string is empty
``````# define a string s
s=""

# try if the string s is empty
if s == "":
print("The string s  is empty")
else:
print("The list s is not  empty")
``````

### Second Method

Try if a list is empty
``````# define a list L
L = list()

# try if the list L is empty by using the len() function
if len(L) == 0:
print("The list  L is empty")
else:
print("The list  L is not  empty")
``````
Try if a string is empty
``````# define a string s
s=""

# try if the string s is empty by using the len() function
if len(s) == 0:
print("The string s  is empty")
else:
print("The list s is not  empty")
``````

Younes Derfoufi

#### Exercise 27

Write a program in Python as a function that calculates the sum of elements in a list of numbers. And another that multiplies all the elements of a list of numbers.

#### Solution

``````# Function that calculate the product of list elements
def mult(l):
m = 1
# run through the list elements
for x in l:
m = m*x
return m
print(mult([2,5,3]))

# Function that calculate the sum of list elements
def sum(l):
s = 0
# run through the list elements
for x in l:
s = s + x
return s
print(sum([2,5,3]))
``````

Younes Derfoufi

#### Exercise 23

Write a program in Python language that asks the user to enter the name of a file and return the extension. Example if the user enters coursPython.pdf the program returns the message "The file extension is .pdf".

#### Solution

`````` # ask user to enter a file name with extension
myFile = input("Enter the file name with extension: ")

# convert the file name to list by choosing the '.' caracter as separator
list = myFile.split(".")

# find the extension of file name
ext = list[-1]
print ("The file extension  is : " + ext)
``````

Younes Derfoufi
Verbatim secures its new portable hard drive with a fingerprint reader
The FingerPrint Secure drive has hardware encryption and fingerprint access.
Known a few years ago for its USB sticks, as well as its blank CDs and DVDs, the manufacturer Verbatim is back on the storage market by presenting to the IFA an original portable hard drive. The FingerPrint Secure is distinguished by a hardware encryption (AES 256 bits), but especially by its built-in fingerprint reader.
would work on a smarter way to display the thumbs-up count collected by a publication, to limit ego wars and deletions of publications.
Bye bye thumb up. Facebook is it about to revolutionize its mode of operation? It could be good. The behemoth of social networks is currently leading tests to show a limited number of "Likes" on a post published in the News Feed column. "Thumbs up" that would be mainly attributed by known contacts of the person browsing the thread of his publications.

This seventy-ninth version of the Mozilla Web browser gives Mac users a head start, a little more trouble with Flash, and smarter PC tab browsing.
Firefox 69 will be deployed tomorrow, Wednesday, September 4th. And if you are in a hurry to get your hands on it, Mozilla already offers a preloading of the installation file on its FTP. Attention, the interface is ... foundry brute. The title of the links is quite clear but if you have any doubt, wait until the update program included in the browser offers the new version.

## Monday, September 2, 2019

#### Exercise 26

Write a program that asks the user to enter a text and return all words beginning with the letter a.

### First method

``````# Ask to type a string text
s = input("Type a string text : ")
# convert a string s to list
s = s.split()
# fetching all list element that beginning with the letter 'a'
for x in s:
if(x[0] == 'a'):
print("The word : ", x, " begin with the letter 'a'")
``````

### Second method

Congress 2019 last March, the highly anticipated HoloLens 2 augmented reality headset from Microsoft will be available in September.
We already knew his price, 3500 dollars. According to Reuters, developers and companies interested in the Microsoft HoloLens 2 headset will be able to pay this amount as early as September to acquire it. Harry Shum, Executive Vice President of Microsoft, said at the World Conference on Artificial Intelligence (WAIC) in Shanghai, without specifying the day of the official release of the augmented reality headset . If the territories concerned have not been specified, France should be among the first served.

## Sunday, September 1, 2019

#### Exercise 25

Write a program that asks the user to enter a word and return the opposite. Example if the user enters the word python, the program returns nohtyp.

### First method

``````# Ask to type a string s
s = input("Type a string s : ")
# getting the reverse of the string s
s1 = s[::-1]

print("The reverse of the string : '",s,"' is : ", s1)
``````

### Second method

``````# Ask to type a string s
s = input("Type a string s : ")
# initialize the reverse of the string s to empty string
rev = ""

# Building the string s in a reversed way
for x in s:
rev = x + rev
print("The reverse of the string : '",s,"' is : ", rev)
``````

Younes Derfoufi

#### Exercise 24

A palindrome is a word whose order of letters remains the same whether it is read from left to right or from right to left. For example: 'laval', 'radar,' sos' ... are palindromes. Write a program in Python that asks the user to enter a word and return it if it is a palindrome or not?

#### Solution

``````# Ask to type a string s
s = input("Type a string s : ")

# getting the reverse of the string s
s1 = s[::-1]

# try if the typed strins s is a palindrome
if(s1 == s):
print("The string : '",s," ' is a palindrome")
else:
print("The string : '",s," ' is not a palindrome")
``````

Younes Derfoufi