0% found this document useful (0 votes)
9 views3 pages

TP 4

The document contains several Python exercises demonstrating functions for user input, list manipulation, and basic data structures. Key functionalities include finding common elements between lists, determining maximum values, checking for unique characters in a string, and conducting a quiz with user responses. Additionally, it showcases how to filter student names based on their scores.

Uploaded by

Shin Ha Ri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

TP 4

The document contains several Python exercises demonstrating functions for user input, list manipulation, and basic data structures. Key functionalities include finding common elements between lists, determining maximum values, checking for unique characters in a string, and conducting a quiz with user responses. Additionally, it showcases how to filter student names based on their scores.

Uploaded by

Shin Ha Ri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

tp4

ex1
def saisir():
n = int(input("n="))
return n

def saisirlt(n):
lt = []
for i in range(n):
lt.insert(i, int(input("lt[" + str(i) + "]=")))

return lt

def commun(n, lt, lt1):


nb = 0
for i in range(len(lt)):
if lt[i] in lt1 and test(lt, i, lt[i]) == False:
nb = nb + 1
print("le nombre des elements en commun est :", nb)
return nb

def test(lt, x, y):

for i in range(x):
if y == lt[i]:
return True
return False

def aff(n, lt, lt1):


max = lt[0]
for i in range(1, n):
if lt[i] > max and not(lt[i] in lt1):
max = lt[i]

for i in range(len(lt1)):
if max < lt1[i] and not(lt1[i] in lt):
max = lt1[i]
print("le nombre maximum est :", max)

def affsd(n, lt, lt1):


for i in range(len(lt)):
if test(lt, i, lt[i]) == False:
print(lt[i])
for i in range(len(lt1)):
if test(lt1, i, lt1[i]) == False and not(lt1[i] in lt):
print(lt1[i])

n = saisir()
lt = saisirlt(n)
lt1 = [0, 12, 13, 45, 50, 87, 55]
nb = commun(n, lt, lt1)
aff(n, lt, lt1)
affsd(n, lt, lt1)

ex2
def hiérogramme(ch):
for i in range(len(ch)):
if test(ch, i, ch[i]) == True:
print("NON")
break
elif test(ch, i, ch[i]) == False and i == (len(ch) - 1):
print("OUI")

def test(ch, n, x):


for i in range(n):
if x == ch[i]:
return True
return False

ch = input("ch=")
nb = hiérogramme(ch)

ex3
from numpy import array

def posez_quest():
n = int(input("entrez le nombre de quest : "))
t = array([{}] * n)
t1 = array([{}] * n)
for i in range(n):
t[i]["labelle"] = input("entrez une question: ")
t[i]["choix"] = input("entrez les choix: ")
t[i]["reponse"] = input("entrez une reponse correcte: ")
print(t[0])
print(t[1])
t1 = t.copy()
nb = 0
for j in range(n):
print(t1[j]["labelle"])
print(t1[j]["choix"])
ch = input("entrez la reponse : ")
if ch == t1[j]["reponse"]:
nb = nb + 1
print("votre score est : ", nb)

return nb

nb = posez_quest()

ex4

etudiant = {
"walid": 15,
"majdi": 12,
"charli": 18,
"david": 14,
"fathi": 16
}
list = []
k = 0
for i, j in etudiant.items():
if j >= 14:
list.insert(k, i)
k = k + 1
print(list)

You might also like