Skip to content
Snippets Groups Projects
Commit b33119a5 authored by Hahn Robin's avatar Hahn Robin
Browse files

Update INF-TC1-td02.ipynb

parent 59809971
No related branches found
No related tags found
No related merge requests found
......@@ -247,7 +247,13 @@
"outputs": [],
"source": [
"def average_grade(L: list)-> int:\n",
" # YOUR CODE HERE\n",
" def average_grade(L:list)-> int:
moyenne = 0
N = len(L)
for student in L:
moyenne+= int(student['note'])
moyenne = moyenne/N
return(moyenne),
" raise NotImplementedError()"
]
},
......@@ -322,7 +328,16 @@
"outputs": [],
"source": [
"def find_maximum_recursive(L: list)-> str:\n",
" # YOUR CODE HERE\n",
" def find_maximum_recursive(L:list)->int:
m = float(L[-1]['note'])
if len(L) == 1:
return float(L[0]['note'])
else:
n = len(L)
L=L[:n-1]
if float(find_maximum_recursive(L))>m:
m = float(find_maximum_recursive(L))
return m,
" raise NotImplementedError()"
]
},
......@@ -371,7 +386,14 @@
"outputs": [],
"source": [
"def find_same_grade(L: list)-> tuple:\n",
" # YOUR CODE HERE\n",
" def find_same_grade(L:list)->tuple:
l=[int(student['note']) for student in L]
S = set({})
for i in range(len(l)):
for j in range(len(l)):
if (l[i],j) in S and i!=j:
return (L[i]['nom'],L[j]['nom'])
S.add((l[i],i)),
" raise NotImplementedError()"
]
},
......@@ -441,7 +463,18 @@
"outputs": [],
"source": [
"def sort_selection(L: list, key=lambda x: x) -> list:\n",
" # YOUR CODE HERE\n",
" def sort_selection(L:list,critere:str)->list:
n = len(L)
for i in range(0,n-1):
minimum = i
for j in range(minimum,n):
if L[j][critere] < L[minimum][critere]:
minimum = j
if min != i:
val = L[i]
L[i] = L[minimum]
L[minimum] = val
return L,
" raise NotImplementedError()"
]
},
......@@ -570,7 +603,9 @@
"source": [
"pile = queue.LifoQueue()\n",
"s = Stack()\n",
"# YOUR CODE HERE\n",
"for etu in students_list:
s.push(etu)
pile.put(etu)",
"raise NotImplementedError()\n",
"\n",
"while not s.is_empty() and not pile.empty():\n",
......@@ -606,7 +641,20 @@
"outputs": [],
"source": [
"class Queue():\n",
" # YOUR CODE HERE\n",
"
class Queue:
def __init__(self):
self.items = []
def push(self,item):
self.items.append(item)
def pop(self):
if not self.is_empty():
return self.items.pop(0)
def peek(self):
if not self.is_empty():
return self.items[0]
def is_empty(self):
return len(self.items) == 0",
" raise NotImplementedError()"
]
},
......@@ -632,7 +680,9 @@
"source": [
"file = queue.Queue()\n",
"f = Queue()\n",
"# YOUR CODE HERE\n",
"for etu in students_list:
f.push(etu)
file.put(etu)",
"raise NotImplementedError()\n",
"\n",
"while not f.is_empty() and not file.empty():\n",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment