Import all
697
Formations/NSI/Bloc1/TD2.ipynb
Normal file
@@ -0,0 +1,697 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Exercice 6"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def cherche(tableau, elem):\n",
|
||||
" \"\"\"Y a-t-il elem dans le tableau\"\"\"\n",
|
||||
" for e in tableau:\n",
|
||||
" if elem == e:\n",
|
||||
" return 1\n",
|
||||
" return 0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1"
|
||||
]
|
||||
},
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"cherche(list(range(50)), 5)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cherche(list(range(50)), 100)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Exercice 7"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 34,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def dico_rec(tableau, elem):\n",
|
||||
" size = len(tableau)\n",
|
||||
" if size == 0:\n",
|
||||
" return 0\n",
|
||||
" \n",
|
||||
" middle = tableau[int(size/2)]\n",
|
||||
" \n",
|
||||
" if elem == middle:\n",
|
||||
" return 1\n",
|
||||
" elif elem > middle:\n",
|
||||
" return dico_rec(tableau[int(size/2)+1:], elem)\n",
|
||||
" elif elem < middle:\n",
|
||||
" return dico_rec(tableau[:int(size/2)], elem)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 45,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1"
|
||||
]
|
||||
},
|
||||
"execution_count": 45,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"dico_rec(list(range(11)), 1)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 42,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1"
|
||||
]
|
||||
},
|
||||
"execution_count": 42,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"dico_rec(list(range(10)), 6)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 37,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0"
|
||||
]
|
||||
},
|
||||
"execution_count": 37,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"dico_rec(list(range(11)), 12)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 38,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0"
|
||||
]
|
||||
},
|
||||
"execution_count": 38,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"dico_rec(list(range(10)), 14)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Triée?"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def is_sorted(tab):\n",
|
||||
" \"\"\" Trie croissant? \"\"\"\n",
|
||||
" for i in range(len(tab)-1):\n",
|
||||
" if tab[i] > tab[i+1]:\n",
|
||||
" return 0\n",
|
||||
" return 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"1"
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"is_sorted(list(range(10)))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"0"
|
||||
]
|
||||
},
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"is_sorted([3, 4, 1, 2])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Tri insertion"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def insert(tab, elem, head=[]):\n",
|
||||
" \"\"\" Insert elem au bon endroit dans tab \n",
|
||||
" \n",
|
||||
" param tab: \n",
|
||||
" param elem: élément à inserer\n",
|
||||
" param head: élément plus petits que elem\n",
|
||||
" \"\"\"\n",
|
||||
" if tab == []:\n",
|
||||
" return head+[elem]\n",
|
||||
" first = tab[0]\n",
|
||||
" if first >= elem:\n",
|
||||
" return head + [elem] + tab\n",
|
||||
" else:\n",
|
||||
" return insert(tab[1:], elem, head+[first])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[1, 2, 4, 5, 6]"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"insert([1, 4, 5, 6], 2)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[0, 1, 4, 5, 6]"
|
||||
]
|
||||
},
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"insert([1, 4, 5, 6], 0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[1, 4, 5, 6, 10]"
|
||||
]
|
||||
},
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"insert([1, 4, 5, 6], 10)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def tri_insertion(tab, out=[]):\n",
|
||||
" \"\"\" Trie par insertion\n",
|
||||
" \n",
|
||||
" param tab\n",
|
||||
" \"\"\"\n",
|
||||
" if tab == []:\n",
|
||||
" return out\n",
|
||||
" elem = tab[0]\n",
|
||||
" new_out = insert(out, elem)\n",
|
||||
" return tri_insertion(tab[1:], new_out)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[1, 2, 3, 4, 6]"
|
||||
]
|
||||
},
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"tri_insertion([3, 4, 2, 6, 1])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[]"
|
||||
]
|
||||
},
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"tri_insertion([])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[3, 3, 5, 6]"
|
||||
]
|
||||
},
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"tri_insertion([3, 3, 5, 6])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Tri selection"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 69,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def split_min(tab, minval=None, head = [], mid_head=[]):\n",
|
||||
" \"\"\" coupecoupe\n",
|
||||
" \n",
|
||||
" return: head, min, tail\n",
|
||||
" \"\"\"\n",
|
||||
" if tab == []:\n",
|
||||
" return head, minval, mid_head\n",
|
||||
" if minval==None:\n",
|
||||
" return split_min(tab[1:], tab[0], mid_head)\n",
|
||||
" \n",
|
||||
" first = tab[0]\n",
|
||||
" if first > minval:\n",
|
||||
" return split_min(tab[1:], minval, head, mid_head+[first])\n",
|
||||
" \n",
|
||||
" return split_min(tab[1:], first , head + [minval] + mid_head, [])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 70,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"([3, 4], 1, [6, 5])"
|
||||
]
|
||||
},
|
||||
"execution_count": 70,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"split_min([3, 4, 1, 6, 5])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 71,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"([6], 5, [])"
|
||||
]
|
||||
},
|
||||
"execution_count": 71,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"split_min([6, 5])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 72,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"([], 5, [6])"
|
||||
]
|
||||
},
|
||||
"execution_count": 72,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"split_min([5, 6])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 73,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"([], 4, [])"
|
||||
]
|
||||
},
|
||||
"execution_count": 73,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"split_min([4])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 88,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def tri_selection(tab):\n",
|
||||
" \"\"\" Pas sur que ce soit vraiment ça qu'on demande \"\"\"\n",
|
||||
" if len(tab)==0:\n",
|
||||
" return []\n",
|
||||
" if len(tab)==1:\n",
|
||||
" return tab\n",
|
||||
" first = tab[0]\n",
|
||||
" head, minval, tail = split_min(tab[1:])\n",
|
||||
" if first > minval:\n",
|
||||
" return [minval]+ tri_selection(head + [first] + tail)\n",
|
||||
" return [first] + tri_selection(tab[1:])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 89,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[1, 2, 3, 4, 6]"
|
||||
]
|
||||
},
|
||||
"execution_count": 89,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"tri_selection([3, 4, 2, 6, 1])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 91,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[]"
|
||||
]
|
||||
},
|
||||
"execution_count": 91,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"tri_selection([])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 92,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[3, 3, 5, 6]"
|
||||
]
|
||||
},
|
||||
"execution_count": 92,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"tri_selection([3, 3, 5, 6])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Tri fusion"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 73,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def fusion(head, tail):\n",
|
||||
" \"\"\" Fusion les 2 tableaux\n",
|
||||
" \n",
|
||||
" param head: liste d'entiers triée\n",
|
||||
" param tail: liste d'entiers triée\n",
|
||||
" return: fusion des deux listes ordonnées\n",
|
||||
" \"\"\"\n",
|
||||
" try:\n",
|
||||
" last_head = head[-1]\n",
|
||||
" except IndexError:\n",
|
||||
" return tail\n",
|
||||
" try:\n",
|
||||
" last_tail= tail[-1]\n",
|
||||
" except IndexError:\n",
|
||||
" return head\n",
|
||||
" \n",
|
||||
" if last_head > last_tail:\n",
|
||||
" return fusion(head[:-1], tail) + [last_head]\n",
|
||||
" return fusion(head, tail[:-1]) + [last_tail]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 74,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[2, 3, 4]"
|
||||
]
|
||||
},
|
||||
"execution_count": 74,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"fusion([3, 4], [2])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 78,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def tri_fusion(tab):\n",
|
||||
" \"\"\"\"\"\"\n",
|
||||
" if len(tab)<2:\n",
|
||||
" return tab\n",
|
||||
" middle = int(len(tab)/2)\n",
|
||||
" head = tri_fusion(tab[middle:])\n",
|
||||
" tail = tri_fusion(tab[:middle])\n",
|
||||
" return fusion(head, tail)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 79,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[1, 2, 3, 5, 5, 19]"
|
||||
]
|
||||
},
|
||||
"execution_count": 79,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"tri_fusion([3, 5, 5, 19, 1, 2])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Tri "
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.1"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
19
Formations/NSI/Bloc1/WEB/DIU-EIL-WEB-test.html
Normal file
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>DIU-EIL : bloc 1, programmation WEB - test automatisés</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="main-test">Tests automatisés</h1>
|
||||
<div id="mocha"></div>
|
||||
|
||||
<script src="https://unpkg.com/chai/chai.js"></script>
|
||||
<script src="https://unpkg.com/mocha/mocha.js"></script>
|
||||
<script src="DIU-EIL-WEB.js"></script>
|
||||
<script src="DIU-EIL-WEB-test.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
62
Formations/NSI/Bloc1/WEB/DIU-EIL-WEB-test.js
Normal file
@@ -0,0 +1,62 @@
|
||||
/* global mocha suite test chai fibonacci */
|
||||
// voir la documentation https://mochajs.org/#running-mocha-in-the-browser
|
||||
|
||||
|
||||
'use strict';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// initialisation de Mocha
|
||||
mocha.setup('tdd');
|
||||
mocha.globals(['__VUE_DEVTOOLS_TOAST__']);
|
||||
mocha.checkLeaks();
|
||||
|
||||
// ////////////////////////////////////////////////////////////////////
|
||||
// Suites de tests
|
||||
// ////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Voir pour la syntaxe des assertions https://www.chaijs.com/api/assert/
|
||||
|
||||
suite('Tests pour la fonction fibonacci', () => {
|
||||
test('Type de résultats : nombre', () => {
|
||||
chai.assert.isNumber(fibonacci(0));
|
||||
});
|
||||
|
||||
test('Paramètre négatif : résultat indéfini', () => {
|
||||
chai.assert.isUndefined(fibonacci(-1));
|
||||
});
|
||||
|
||||
test('Paramètre mauvais type : résultat indéfini', () => {
|
||||
chai.assert.isUndefined(fibonacci({}));
|
||||
chai.assert.isUndefined(fibonacci(() => 0));
|
||||
chai.assert.isUndefined(fibonacci([]));
|
||||
chai.assert.isUndefined(fibonacci('test'));
|
||||
chai.assert.isUndefined(fibonacci());
|
||||
chai.assert.isUndefined(fibonacci(true));
|
||||
});
|
||||
|
||||
test('Test valeurs initiales', () => {
|
||||
chai.assert.strictEqual(fibonacci(0), 0);
|
||||
chai.assert.strictEqual(fibonacci(1), 1);
|
||||
chai.assert.strictEqual(fibonacci(2), 1);
|
||||
});
|
||||
|
||||
test('Test valeur haute ', () => {
|
||||
chai.assert.strictEqual(fibonacci(30), 832040);
|
||||
});
|
||||
});
|
||||
|
||||
suite('Tests pour la fonction fibonacci', () => {
|
||||
test('Start est à 0 par defaut', () => {
|
||||
chai.assert.strictEqual(range(0,10), range(10));
|
||||
});
|
||||
test('Comportement attendu', () => {
|
||||
chai.assert.strictEqual(range(10), [0,1,2,3,4,5,6,8,9]);
|
||||
chai.assert.Equal(range(10, 4, 2) == [4,6,8]);
|
||||
});
|
||||
test('Liste vide quand end > start', () => {
|
||||
chai.assert.Equal(range(-2, 0), []);
|
||||
});
|
||||
})
|
||||
// Lancement des tests
|
||||
mocha.run();
|
||||
}, false);
|
||||
17
Formations/NSI/Bloc1/WEB/DIU-EIL-WEB.css
Normal file
@@ -0,0 +1,17 @@
|
||||
.soft-btn {
|
||||
background-color:gray;
|
||||
border: none;
|
||||
color: white;
|
||||
padding: 1em 2em ;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.dot {
|
||||
position: absolute;
|
||||
pointer-events: none;
|
||||
height: 50px;
|
||||
width: 50px;
|
||||
border-radius: 25px;
|
||||
background-color: #bbb;
|
||||
}
|
||||
|
||||
66
Formations/NSI/Bloc1/WEB/DIU-EIL-WEB.html
Normal file
@@ -0,0 +1,66 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>DIU-EIL : bloc 1 - introduction à la programmation WEB</title>
|
||||
<link href="DIU-EIL-WEB.css" rel="stylesheet" media="all" type="text/css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header id="header">
|
||||
<h1>Activité pratique «programmation web»</h1>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
|
||||
<nav id="menu">
|
||||
<h2>Menu</h2>
|
||||
<ul>
|
||||
<li><a href="#content-partie-1">Partie 1</a></li>
|
||||
<li><a href="#content-partie-2">Partie 2</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<section id="container">
|
||||
|
||||
<section id="content-partie-1">
|
||||
|
||||
<h2>Partie 1</h2>
|
||||
|
||||
<h3>Un premier boutton</h3>
|
||||
<div>
|
||||
<button id="btn-exec">Exécuter</button>
|
||||
</div>
|
||||
|
||||
<h3>Un formulaire pour une fonction JS</h3>
|
||||
<div>
|
||||
<div>
|
||||
<ul>
|
||||
<li>Stop<input type="text" id="input-range-stop" value="10"/></li>
|
||||
<li>Start<input type="text" id="input-range-start" value=""/></li>
|
||||
<li>Step<input type="text" id="input-range-step" value=""/></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<button class="soft-btn" id="btn-range-eval">Range</button>
|
||||
<button class="soft-btn" id="btn-range-reset">Reset</button>
|
||||
</div>
|
||||
|
||||
<code id="output"></code>
|
||||
|
||||
</section>
|
||||
|
||||
<section id="content-partie-2">
|
||||
<h2>Partie 2</h2>
|
||||
|
||||
</section>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer id="footer">
|
||||
Contenus à partir de Pierre-Antoine Champin, Emmanuel Coquery, Fabien Duchateau et Romuald Thion.
|
||||
</footer>
|
||||
|
||||
<script src="DIU-EIL-WEB.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
55
Formations/NSI/Bloc1/WEB/DIU-EIL-WEB.js
Normal file
@@ -0,0 +1,55 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
|
||||
'use strict';
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////////////
|
||||
// Exercice : bases du langage et utilisation de la console
|
||||
// //////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function fibonacci(n) {
|
||||
if (!Number.isInteger(n) || n < 0) {
|
||||
return undefined;
|
||||
}
|
||||
if (n === 0 || n === 1) {
|
||||
return n;
|
||||
}
|
||||
|
||||
return (fibonacci(n - 1) + fibonacci(n - 2));
|
||||
}
|
||||
|
||||
|
||||
// range //////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Fonction range, pas trop de choix ici dans l'écriture
|
||||
function range(stop, start = 0, step = 1) {
|
||||
const res = [];
|
||||
|
||||
// je mets une "garde" ici pour éviter des boucles sans fin si step est nul ou négatif
|
||||
if (!Number.isInteger(step) || step < 1) return res;
|
||||
|
||||
// for "à l'ancienne" du C ou java. On ne peut pas faire bien mieux
|
||||
for (let i = start; i < stop; i += step) {
|
||||
res.push(i);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////////////
|
||||
// Exercice : Téléchargement asynchrone
|
||||
// //////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
function download_json(callback) {
|
||||
const url = 'https://perso.liris.cnrs.fr/romuald.thion/files/Enseignement/DIU-EIL/DIU-EIL-WEB.json';
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(callback)
|
||||
.catch(console.error);
|
||||
}
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////////////
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
console.log('Document entièrement chargé.');
|
||||
document.getElementById('btn-exec').onclick= () => alert('clic');
|
||||
}, false);
|
||||
35
Formations/NSI/Bloc1/WEB/SuperTable/index.html
Executable file
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<title>L'apprentissage de Linux</title>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Super table</h1>
|
||||
|
||||
<nav>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<section id="corps">
|
||||
<table id="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Firstname</th>
|
||||
<th>Lastname</th>
|
||||
<th>Age</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="datatable">
|
||||
</tbody>
|
||||
</table>
|
||||
<button id="addRow" type="button">Ajouter ligne</button>
|
||||
</section>
|
||||
<footer>
|
||||
</footer>
|
||||
</body>
|
||||
<script src="script.js"></script>
|
||||
</html>
|
||||
103
Formations/NSI/Bloc1/WEB/SuperTable/script.js
Normal file
@@ -0,0 +1,103 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
|
||||
'use strict';
|
||||
|
||||
let datas = [
|
||||
{
|
||||
firstname: "Jill",
|
||||
lastname: "Smith",
|
||||
age: 50
|
||||
},
|
||||
{
|
||||
firstname: "Eve",
|
||||
lastname: "Jackson",
|
||||
age: 94
|
||||
},
|
||||
]
|
||||
|
||||
let editing = false;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
updateTable(datas);
|
||||
//console.log(Array.from(document.getElementsByClassName('modifier')));
|
||||
document.getElementById('addRow').onclick = () => appendQueryLine();
|
||||
}, false);
|
||||
|
||||
function toggleEditing() {
|
||||
editing = !editing
|
||||
}
|
||||
|
||||
function feedDatas (datas) {
|
||||
return datas.reduce( (acc, d) => {
|
||||
return acc.concat(`<tr>
|
||||
<th>${d.firstname}</th>
|
||||
<th>${d.lastname}</th>
|
||||
<th>${d.age}</th>
|
||||
<th><button class="modifier">Mod</button><button class="remover">Del</button></th>
|
||||
</tr>`)
|
||||
}, "")
|
||||
}
|
||||
|
||||
function updateTable () {
|
||||
let tbody = document.getElementById("datatable");
|
||||
tbody.innerHTML = feedDatas(datas)
|
||||
Array.from(document.getElementsByClassName('modifier')).map(d => d.onclick = () => modifyPersonne(d));
|
||||
}
|
||||
|
||||
function appendQueryLine () {
|
||||
if (!editing) {
|
||||
editing = true
|
||||
let tbody = document.getElementById("datatable");
|
||||
tbody.innerHTML += `<tr>
|
||||
<th><input id="firstname"></input></th>
|
||||
<th><input id="lastname"></input></th>
|
||||
<th><input id="age"></input></th>
|
||||
<th><button id="save">Ok</button><button id="cancel">Ann</button></th>
|
||||
</tr>`
|
||||
document.getElementById('save').onclick= () => savePersonne();
|
||||
document.getElementById('cancel').onclick= () => removeQueryLine();
|
||||
} else {
|
||||
console.log("Already editing")
|
||||
}
|
||||
}
|
||||
|
||||
function removeQueryLine () {
|
||||
if (editing) {
|
||||
feedDatas(datas)
|
||||
updateTable()
|
||||
toggleEditing()
|
||||
}
|
||||
}
|
||||
|
||||
function modifyPersonne (d) {
|
||||
toggleEditing()
|
||||
let cells = d.parentElement.parentElement.children
|
||||
|
||||
d.parentElement.innerHTML = `<button id="save">Ok</button><button id="cancel">Ann</button>`
|
||||
document.getElementById('save').onclick= () => savePersonne();
|
||||
document.getElementById('cancel').onclick= () => removeQueryLine();
|
||||
|
||||
let firstname = cells[0].firstChild.nodeValue
|
||||
let lastname = cells[1].firstChild.nodeValue
|
||||
let age = cells[2].firstChild.nodeValue
|
||||
|
||||
cells[0].innerHTML = `<input id="firstname" value=${firstname} ></input></th>`
|
||||
cells[1].innerHTML = `<input id="lastname" value=${lastname} ></input></th>`
|
||||
cells[2].innerHTML = `<input id="age" value=${age} ></input></th>`
|
||||
}
|
||||
|
||||
function savePersonne () {
|
||||
let firstname = document.getElementById("firstname");
|
||||
let lastname = document.getElementById("lastname");
|
||||
let age = document.getElementById("age");
|
||||
datas.push(
|
||||
{
|
||||
firstname: firstname.value,
|
||||
lastname: lastname.value,
|
||||
age: age.value
|
||||
}
|
||||
)
|
||||
updateTable()
|
||||
toggleEditing()
|
||||
}
|
||||
|
||||
53
Formations/NSI/Bloc1/WEB/SuperTable/style.css
Executable file
@@ -0,0 +1,53 @@
|
||||
body
|
||||
{
|
||||
margin: auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
section
|
||||
{
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
|
||||
thead
|
||||
{
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
th
|
||||
{
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
input
|
||||
{
|
||||
width: 90px;
|
||||
}
|
||||
|
||||
button
|
||||
{
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
#mod
|
||||
{
|
||||
background-color: yellow;
|
||||
}
|
||||
|
||||
#del
|
||||
{
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
#cancel
|
||||
{
|
||||
background-color: red;
|
||||
}
|
||||
|
||||
#save
|
||||
{
|
||||
background-color: yellow;
|
||||
}
|
||||
|
||||
42
Formations/NSI/Bloc1/WEB/heros/style.css
Executable file
@@ -0,0 +1,42 @@
|
||||
body
|
||||
{
|
||||
margin: 0px;
|
||||
margin: auto;
|
||||
max-width: 50rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
section
|
||||
{
|
||||
height: 100vh;
|
||||
max-width: 50rem;
|
||||
}
|
||||
|
||||
p
|
||||
{
|
||||
text-align: center;
|
||||
margin-top: 50vh; /* poussé de la moitié de hauteur de viewport */
|
||||
}
|
||||
|
||||
nav
|
||||
{
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
a
|
||||
{
|
||||
text-decoration: none;
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
li:nth-child(2n+1) > a
|
||||
{
|
||||
background-color: lightgreen;
|
||||
border-radius: 60px;
|
||||
}
|
||||
li:nth-child(2n) > a
|
||||
{
|
||||
background-color: lightblue;
|
||||
border-radius: 60px;
|
||||
}
|
||||
204
Formations/NSI/Bloc1/WEB/heros/sujet.html
Normal file
@@ -0,0 +1,204 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<title>Page HTML dont vous êtes le héros</title>
|
||||
</head>
|
||||
<body>
|
||||
<section id="sec1">
|
||||
<p>1. Alors que vous pénétrez dans les ruines du donjon,
|
||||
apparemment abandonnées,
|
||||
la lourde grille se referme derrière vous, comme par magie.
|
||||
Il va vous falloir trouver une autre sortie !</p>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="#sec2">Rendez vous au 2</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</section>
|
||||
|
||||
<section id="sec2">
|
||||
<p>2. Vous êtes dans le hall d'entrée.
|
||||
La porte sud est toujours condamnée par une grille,
|
||||
mais trois autres portes sont encores ouvertes.</p>
|
||||
<nav><ul>
|
||||
<li><a href="#sec8">Pour aller à l'ouest, rendez vous au 8</a></li>
|
||||
<li><a href="#sec14">Pour aller au nord, rendez vous au 14</a></li>
|
||||
<li><a href="#sec10">Pour aller à l'est, rendez vous au 10</a></li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec3">
|
||||
<p>3. Plus au sud, un ébouli vous empêche de poursuivre plus loin.</p>
|
||||
<nav><ul>
|
||||
<li>Pour revenir sur vos pas, rendez vous au 16</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec4">
|
||||
<p>4. Vous entrez dans une grande pièce octogonale,
|
||||
munie de trois portes.</p>
|
||||
<nav><ul>
|
||||
<li>Pour aller au nord, rendez vous au 17</li>
|
||||
<li>Pour aller à l'est, rendez vous au 14</li>
|
||||
<li>Pour aller au sud, rendez vous au 8</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec5">
|
||||
<p>5. Au centre de la pièce se trouve une fosse sombre
|
||||
d'où sortent des grognements inquiétants.
|
||||
Au bord, un étroit passage relie les deux seules issues de la pièce.</p>
|
||||
<nav><ul>
|
||||
<li>Pour aller à l'ouest, rendez vous au 12</li>
|
||||
<li>Pour aller au sud, rendez vous au 9</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec6">
|
||||
<p>6. Vous êtes au pied d'un escalier de pierre qui monte vers l'est.
|
||||
Un couloir humide part vers le nord.</p>
|
||||
<nav><ul>
|
||||
<li>Pour aller au nord, rendez vous au 18</li>
|
||||
<li>Pour monter l'escalier, rendez vous au 16</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec7">
|
||||
<p>7. Vous marchez dans un couloit étroit qui tourne à angle droit.</p>
|
||||
<nav><ul>
|
||||
<li>Pour aller à l'ouest, rendez vous au 15</li>
|
||||
<li>Pour aller au sud, rendez vous au 11</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec8">
|
||||
<p>8. Vous êtes dans une salle sombre dont les seules issues sont
|
||||
à l'est et au nord.</p>
|
||||
<nav><ul>
|
||||
<li>Pour aller au nord, rendez vous au 4</li>
|
||||
<li>Pour aller à l'est, rendez vous au 2</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec9">
|
||||
<p>9. Vous vous trouvez dans une grande pièce circulaire,
|
||||
percée de trois portes.</p>
|
||||
<nav><ul>
|
||||
<li>Pour aller à l'ouest, rendez vous au 17</li>
|
||||
<li>Pour aller au nord, rendez vous au 5</li>
|
||||
<li>Pour aller à l'est, rendez vous au 18</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec10">
|
||||
<p>10. Ce couloir est un cul de sac.</p>
|
||||
<nav><ul>
|
||||
<li>Pour revenir sur vos pas, rendez vous au 2</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec11">
|
||||
<p>11. Cette salle a dû être autrefois une salle des gardes.
|
||||
Deux portes donnent vers l'ouest et le nord,
|
||||
tandis qu'une échelle au sud permet de monter sur les murailles.</p>
|
||||
<nav><ul>
|
||||
<li>Pour aller à l'ouest, rendez vous au 18</li>
|
||||
<li>Pour aller au nord, rendez vous au 7</li>
|
||||
<li>Pour monter à l'échelle, rendez vous au 16</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec12">
|
||||
<p>12. Vous marchez le long d'un large couloir
|
||||
formant une courbe régulière.</p>
|
||||
<nav><ul>
|
||||
<li>Pour aller à l'est, rendez vous au 5</li>
|
||||
<li>Pour aller au sud, rendez vous au 17</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec13">
|
||||
<p>13. Vous attendez que vos yeux s'habituent à la lumière du soleil
|
||||
avant d'oser y croire, mais ça y est :
|
||||
vous êtes sorti du donjon !</p>
|
||||
</section>
|
||||
|
||||
<section id="sec14">
|
||||
<p>14. Vous êtes au pied d'une haute tour ronde.
|
||||
Deux portes donnent à l'ouest et au sud,
|
||||
et au centre, un escalier en colimaçon monte vers
|
||||
l'étage supérieur.</p>
|
||||
<nav><ul>
|
||||
<li>Pour aller à l'ouest, rendez vous au 4</li>
|
||||
<li>Pour aller au sud, rendez vous au 2</li>
|
||||
<li>Pour monter l'escalier, rendez vous au 19</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec15">
|
||||
<p>15. Vous êtes dans un grand hall,
|
||||
semblable à celui par lequel vous êtes entré dans le donjon.
|
||||
En plus de la porte par laquelle vous êtes arrivé à l'est,
|
||||
une lourde porte occupe la majeure partie du mur nord.</p>
|
||||
<nav><ul>
|
||||
<li>Pour aller au nord, rendez vous au 13</li>
|
||||
<li>Pour aller à l'est, rendez vous au 7</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec16">
|
||||
<p>16. Vous marchez sur ce qui doit être l'ancien chemin de ronde.
|
||||
L'à-pic vertigineux rend hélas impossible
|
||||
toute fuite depuis cet endroit.
|
||||
À l'extrémité nord, une échelle redescend à l'intérieur du donjon,
|
||||
tandis qu'un escalier de pierre descend vers l'ouest.
|
||||
Le chemin de ronde continue vers le sud.</p>
|
||||
<nav><ul>
|
||||
<li>Pour aller à l'ouest, rendez vous au 6</li>
|
||||
<li>Pour aller au nord, rendez vous au 11</li>
|
||||
<li>Pour aller au sud, rendez vous au 3</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec17">
|
||||
<p>17. Vous êtes dans une grand pièce,
|
||||
faiblement éclairée par des fenêtres grillagées infranchissables.
|
||||
Vous apercevez trois portes.</p>
|
||||
<nav><ul>
|
||||
<li>Pour aller au nord, rendez vous au 12</li>
|
||||
<li>Pour aller à l'est, rendez vous au 9</li>
|
||||
<li>Pour aller au sud, rendez vous au 4</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec18">
|
||||
<p>18. La lumière vous aveugle et
|
||||
vous croyez un moment avoir trouvé la sortie.
|
||||
Vous êtes en fait dans un ancien jardin intérieur,
|
||||
comme en témoignent les terre-pleins envahis par les mauvaises herbes
|
||||
et une fontaine asséchée.
|
||||
Sous les arcades, vous distinguez trois portes.</p>
|
||||
<nav><ul>
|
||||
<li>Pour aller à l'ouest, rendez vous au 9</li>
|
||||
<li>Pour aller à l'est, rendez vous au 11</li>
|
||||
<li>Pour aller au sud, rendez vous au 6</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
<section id="sec19">
|
||||
<p>19. Du sommet de la tour, vous pouvez voir la totalité du donjon,
|
||||
entouré de douves profondes.
|
||||
En plus du pont levis par lequel vous êtes entré, au sud,
|
||||
vous en apercevez un autre, sur la face nord.
|
||||
Votre espoir de fuite ?
|
||||
</p>
|
||||
<nav><ul>
|
||||
<li>Pour redescendre, rendez vous au 14</li>
|
||||
</ul></nav>
|
||||
</section>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
4
Formations/NSI/Bloc1/WEB/index.rst
Normal file
@@ -0,0 +1,4 @@
|
||||
Notes du jours 2: WEB
|
||||
#####################
|
||||
|
||||
CSS zen garden
|
||||
BIN
Formations/NSI/Bloc1/WEB/sujet/assets/images/IUTLyon1.jpg
Executable file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
Formations/NSI/Bloc1/WEB/sujet/assets/images/IUTLyon1.png
Executable file
|
After Width: | Height: | Size: 14 KiB |
BIN
Formations/NSI/Bloc1/WEB/sujet/assets/images/NewTux.png
Executable file
|
After Width: | Height: | Size: 12 KiB |
BIN
Formations/NSI/Bloc1/WEB/sujet/assets/images/arch-logo.jpg
Executable file
|
After Width: | Height: | Size: 935 B |
BIN
Formations/NSI/Bloc1/WEB/sujet/assets/images/debian-logo.png
Executable file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
Formations/NSI/Bloc1/WEB/sujet/assets/images/fondBeige.jpg
Executable file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
Formations/NSI/Bloc1/WEB/sujet/assets/images/linux-mint-logo.jpg
Executable file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
Formations/NSI/Bloc1/WEB/sujet/assets/images/mageia-logo.png
Executable file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
Formations/NSI/Bloc1/WEB/sujet/assets/images/mint-logo.jpg
Executable file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
Formations/NSI/Bloc1/WEB/sujet/assets/images/ubuntu-logo.jpg
Executable file
|
After Width: | Height: | Size: 1.2 KiB |
100
Formations/NSI/Bloc1/WEB/sujet/assets/style.css
Executable file
@@ -0,0 +1,100 @@
|
||||
body
|
||||
{
|
||||
margin: auto;
|
||||
max-width: 60rem;
|
||||
}
|
||||
|
||||
header
|
||||
{
|
||||
border-bottom: 2px solid green;
|
||||
}
|
||||
|
||||
header>img,h1
|
||||
{
|
||||
display: inline;
|
||||
}
|
||||
|
||||
nav
|
||||
{
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
nav>ul
|
||||
{
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
nav>ul>li
|
||||
{
|
||||
display: inline;
|
||||
color: green;
|
||||
border: solid;
|
||||
border-width: 2px;
|
||||
border-top-left-radius: 5px;
|
||||
border-top-right-radius: 5px;
|
||||
}
|
||||
nav>ul>li:hover
|
||||
{
|
||||
background-color: green;
|
||||
}
|
||||
nav>ul>li>a
|
||||
{
|
||||
color: black;
|
||||
text-decoration: none;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
|
||||
section
|
||||
{
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
article
|
||||
{
|
||||
float: left;
|
||||
width: 65%;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
aside
|
||||
{
|
||||
float: right;
|
||||
width: 30%;
|
||||
background-color: lightgreen;
|
||||
border: unset;
|
||||
border-radius: 10px;
|
||||
padding: 10px;
|
||||
border-radius: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
#logos_distrib
|
||||
{
|
||||
background-color: white;
|
||||
text-align: center;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
footer
|
||||
{
|
||||
clear: left;
|
||||
display: block;
|
||||
border-top: 2px solid green;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
footer>ul>li
|
||||
{
|
||||
/*border: solid;*/
|
||||
display: inline;
|
||||
padding: 0px 10px;
|
||||
}
|
||||
footer>ul>li:first-child
|
||||
{
|
||||
border-right: 2px solid black;
|
||||
}
|
||||
footer>ul>li:last-child
|
||||
{
|
||||
border-left: 2px solid black;
|
||||
}
|
||||
|
||||
85
Formations/NSI/Bloc1/WEB/sujet/index.html
Executable file
@@ -0,0 +1,85 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" type="text/css" href="assets/style.css">
|
||||
<title>L'apprentissage de Linux</title>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<img src="assets/images/NewTux.png" alt="Le Pingouin de Linux" />
|
||||
<h1>Linux à l'IUT</h1>
|
||||
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="#">Accueil</a></li>
|
||||
<li><a href="#">SE Linux</a></li>
|
||||
<li><a href="#">Programmation Système</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<section id="corps">
|
||||
|
||||
<article>
|
||||
<h1>Historique de l'enseignement de linux à l'IUT</h1>
|
||||
<p>Montius nos tumore inusitato quodam et novo ut rebellis et maiestati
|
||||
recalcitrantes Augustae per haec quae strepit incusat iratus nimirum quod
|
||||
contumacem praefectum, quid rerum ordo postulat ignorare dissimulantem
|
||||
formidine tenus iusserim custodiri.</p>
|
||||
|
||||
<p>Accedat huc suavitas quaedam oportet sermonum atque morum, haudquaquam
|
||||
mediocre condimentum amicitiae. Tristitia autem et in omni re severitas habet
|
||||
illa quidem gravitatem, sed amicitia remissior esse debet et liberior et
|
||||
dulcior et ad omnem comitatem facilitatemque proclivior.</p>
|
||||
|
||||
<p>Circa hos dies Lollianus primae lanuginis adulescens, Lampadi filius ex
|
||||
praefecto, exploratius causam Maximino spectante, convictus codicem noxiarum
|
||||
artium nondum per aetatem firmato consilio descripsisse, exulque mittendus,
|
||||
ut sperabatur, patris inpulsu provocavit ad principem, et iussus ad eius
|
||||
comitatum duci, de fumo, ut aiunt, in flammam traditus Phalangio Baeticae
|
||||
consulari cecidit funesti carnificis manu.</p>
|
||||
|
||||
<p>Et quia Mesopotamiae tractus omnes crebro inquietari sueti praetenturis
|
||||
et stationibus servabantur agrariis, laevorsum flexo itinere Osdroenae
|
||||
subsederat extimas partes, novum parumque aliquando temptatum commentum
|
||||
adgressus. quod si impetrasset, fulminis modo cuncta vastarat. erat autem
|
||||
quod cogitabat huius modi.</p>
|
||||
|
||||
<p>Eodem tempore Serenianus ex duce, cuius ignavia populatam in Phoenice
|
||||
Celsen ante rettulimus, pulsatae maiestatis imperii reus iure postulatus
|
||||
ac lege, incertum qua potuit suffragatione absolvi, aperte convictus familiarem
|
||||
suum cum pileo, quo caput operiebat, incantato vetitis artibus ad templum
|
||||
misisse fatidicum, quaeritatum expresse an ei firmum portenderetur imperium,
|
||||
ut cupiebat, et cunctum.</p>
|
||||
|
||||
</article>
|
||||
|
||||
<aside>
|
||||
<section>
|
||||
<h1>Choisir sa distribution</h1>
|
||||
<p id="logos_distrib">
|
||||
<img src="assets/images/mint-logo.jpg" alt="Logo de Mint" />
|
||||
<img src="assets/images/debian-logo.png" alt="Logo de Debian" />
|
||||
<img src="assets/images/ubuntu-logo.jpg" alt="Logo d'Ubuntu" />
|
||||
<img src="assets/images/mageia-logo.png" alt="Logo de Mageia" />
|
||||
<img src="assets/images/arch-logo.jpg" alt="Logo d'Arch-linux" />
|
||||
</p>
|
||||
<p>Des étudiants et des enseignants peuvent vous conseiller.</p>
|
||||
<p>Vous pouvez également consulter <a href="http://distrowatch.com/dwres.php?resource=major&language=FR">ce site</a>
|
||||
pour commencer à vous faire une idée.</p>
|
||||
</section><section>
|
||||
<h1>Installer Linux</h1>
|
||||
<p>Avec une machine virtuelle, en dual-boot, sur un live-CD ou comme seul système sur vos machines, peu importe. Ce qui compte, c'est de pratiquer (dans le terminal).</p>
|
||||
</section>
|
||||
</aside>
|
||||
</section>
|
||||
<footer>
|
||||
<ul>
|
||||
<li>Réalisé avec Notepad++</li>
|
||||
<li>HTML5 valide</li>
|
||||
<li>CSS valide</li>
|
||||
</ul>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
BIN
Formations/NSI/Bloc1/diubloc1-files-td3/collisions.pdf
Normal file
3246
Formations/NSI/Bloc1/diubloc1-files-td3/dico.en2fr
Normal file
16020
Formations/NSI/Bloc1/diubloc1-files-td3/dico.english
Normal file
61
Formations/NSI/Bloc1/diubloc1-files-td3/diu-dico-english.py
Normal file
@@ -0,0 +1,61 @@
|
||||
#! /usr/bin/env python3
|
||||
"""
|
||||
python3 diu-dico-english.py
|
||||
"""
|
||||
__author__ = "Laure Gonnord"
|
||||
__copyright__ = "Univ Lyon1, 2019"
|
||||
|
||||
import time
|
||||
|
||||
# Comparaison rapide liste/dictionnaires.
|
||||
# Nécessite le fichier dico.en2fr récupéré de http://www.june29.com/IDP/files/French.txt (on a enlevé les lignes du début)
|
||||
|
||||
|
||||
# Liste
|
||||
def update_list(mot, trad, mylist):
|
||||
mylist.append((mot, trad))
|
||||
|
||||
|
||||
def load_list(nomFichier, dico):
|
||||
"""
|
||||
charge les mots du fichier dans la liste
|
||||
"""
|
||||
with open(nomFichier) as fichier:
|
||||
for ligne in fichier:
|
||||
(mot, trad) = ligne.strip().split("\t")
|
||||
# print(mot, trad)
|
||||
update_list(mot, trad, dico)
|
||||
|
||||
|
||||
def search_tuple(tups, elem):
|
||||
for (mot, trad) in tups:
|
||||
if (mot == elem):
|
||||
return trad
|
||||
raise Exception("search tuple: not found")
|
||||
|
||||
|
||||
# Dictionnaire
|
||||
# TODO : update, load.
|
||||
|
||||
|
||||
################## Programme principal ######################
|
||||
|
||||
|
||||
fichier = 'dico.en2fr'
|
||||
NBTRIES = 10000
|
||||
|
||||
# initialisation et chargement de la liste
|
||||
mylist = []
|
||||
startTime = time.time()
|
||||
load_list(fichier, mylist)
|
||||
endTime = time.time()
|
||||
print("La liste est chargée en (s)", (endTime - startTime))
|
||||
print("la traduction de dog est ", search_tuple(mylist, "dog"))
|
||||
|
||||
startTime = time.time()
|
||||
for i in range(NBTRIES):
|
||||
search_tuple(mylist, "house")
|
||||
endTime = time.time()
|
||||
print("mes recherches ont coûté ", (endTime - startTime))
|
||||
|
||||
# TODO : faire la même chose avec un dictionnaire
|
||||
182
Formations/NSI/Bloc1/diubloc1-files-td3/diu-dico-hash.py
Normal file
@@ -0,0 +1,182 @@
|
||||
#! /usr/bin/env python3
|
||||
"""
|
||||
python3 diu-dico-hash
|
||||
"""
|
||||
__author__ = "Nicolas Pronost and Laure Gonnord"
|
||||
__copyright__ = "Univ Lyon1, 2019"
|
||||
|
||||
from libdiulistechainee import * # une librairie maison de listes triées.
|
||||
import matplotlib.pyplot as plt
|
||||
import time
|
||||
import sys
|
||||
|
||||
sys.setrecursionlimit(10000)
|
||||
|
||||
################## Constantes ######################
|
||||
|
||||
TAILLE_TABLE = 308
|
||||
|
||||
################## Fonction de hachage ######################
|
||||
|
||||
|
||||
def asciss(mot):
|
||||
h = 0
|
||||
for c in mot:
|
||||
h += ord(c) - 96
|
||||
return h
|
||||
|
||||
|
||||
def hash(mot):
|
||||
return asciss(mot) % TAILLE_TABLE
|
||||
|
||||
|
||||
################## Construction de la table ######################
|
||||
|
||||
|
||||
def init_ht(ht):
|
||||
"""
|
||||
Construit une liste de TAILLE_TABLE listes chainees (triées)
|
||||
une nouvelle liste chainee sera obtenue en appelant ListeChainee()
|
||||
"""
|
||||
ht = [ListeChainee() for i in range(TAILLE_TABLE)]
|
||||
return ht
|
||||
|
||||
|
||||
def update_ht(mot, ht):
|
||||
"""
|
||||
Ajoute le mot dans la liste chainee triee à la case d'index hash(mot).
|
||||
Utiliser ajouterDansListeTriee.
|
||||
"""
|
||||
ht[hash(mot)].ajouterEnTete(mot)
|
||||
|
||||
|
||||
def load_ht(nomFichier, ht):
|
||||
"""
|
||||
Ajoute les mots du fichier dans la table de hachage
|
||||
"""
|
||||
with open(nomFichier) as fichier:
|
||||
for ligne in fichier:
|
||||
update_ht(ligne[:-1], ht)
|
||||
|
||||
|
||||
################## Fonctionnalités de la table ######################
|
||||
|
||||
|
||||
def afficheCollisions(ht):
|
||||
"""
|
||||
Imprime la taille de chaque liste contenue dans les cases de ht
|
||||
Utiliser la méthode nbElements()
|
||||
"""
|
||||
for lc in ht:
|
||||
print(lc.nbElements())
|
||||
|
||||
|
||||
def nombresCollisions(ht):
|
||||
"""
|
||||
Calcule et retourne la taille des listeschainées
|
||||
pour chaque case de la table
|
||||
selon une forme utile pour les graphiques, ie :
|
||||
- la premiere liste contient les indices des cases
|
||||
- la deuxième la taille de la liste contenue.
|
||||
Utiliser la méthode nbElements()
|
||||
"""
|
||||
res = ([], [])
|
||||
for k,v in enumerate(ht):
|
||||
res[0].append(k)
|
||||
res[1].append(v.nbElements())
|
||||
return res
|
||||
|
||||
|
||||
def max_hash(nomFichier):
|
||||
"""
|
||||
Retourne le couple (mot_max,hmax) du plus "grand" mot (au sens de asciss)
|
||||
et sa valeur de hachage
|
||||
"""
|
||||
mot_max = ""
|
||||
hmax = 0
|
||||
with open(nomFichier) as fichier:
|
||||
for ligne in fichier:
|
||||
mot = ligne[:-1]
|
||||
ha = hash(mot)
|
||||
if ha > hmax:
|
||||
hmax = ha
|
||||
mot_max = mot
|
||||
return (mot_max, hmax)
|
||||
|
||||
|
||||
####### Quelques fonctions de stats/dessin de figures qui font varier la taille de ht
|
||||
|
||||
|
||||
def stats_load(fichier):
|
||||
global TAILLE_TABLE
|
||||
ht = []
|
||||
# affichage temps exec en fct de la taille de la table
|
||||
plt.figure()
|
||||
toplot = []
|
||||
tailles_table = [10, 50, 100, 200, 400]
|
||||
for TAILLE_TABLE in tailles_table:
|
||||
ht.clear()
|
||||
startTime = time.time()
|
||||
init_ht(ht)
|
||||
load_ht(fichier, ht)
|
||||
toplot.append(time.time() - startTime)
|
||||
plt.plot(tailles_table, toplot, "-k")
|
||||
plt.title("Temps d'exécution vs. taille table")
|
||||
plt.grid(True)
|
||||
plt.show()
|
||||
|
||||
|
||||
# Affichage graphe du nombre de collisions pour plusieurs tailles.
|
||||
def stats_collisions(fichier):
|
||||
global TAILLE_TABLE
|
||||
ht = []
|
||||
plt.figure()
|
||||
tailles_table = [10, 50, 100, 200, 400]
|
||||
colors_plot = ["r", "b", "k", "g", "m"]
|
||||
for i in range(len(tailles_table)):
|
||||
TAILLE_TABLE = tailles_table[i]
|
||||
init_ht(ht)
|
||||
load_ht(fichier, ht)
|
||||
(axisX, axisY) = nombresCollisions(ht)
|
||||
plt.plot(axisX, axisY, colors_plot[i], label="taille " + str(TAILLE_TABLE))
|
||||
plt.grid(True)
|
||||
plt.legend(loc="upper right")
|
||||
# plt.title('Nb de collisions vs. taille table')
|
||||
plt.show()
|
||||
|
||||
|
||||
################## Programme principal ######################
|
||||
|
||||
|
||||
ht = [] # Ma table de hachage est une liste de listes chainées
|
||||
fichier = "dico.english"
|
||||
|
||||
# initialisation et chargement de la table
|
||||
ht = init_ht(ht)
|
||||
load_ht(fichier, ht)
|
||||
|
||||
# Affichage console du nombre de collisions
|
||||
#afficheCollisions(ht)
|
||||
|
||||
# A décommenter (il faut numpy et mathplotlib)
|
||||
|
||||
# # Affichage graphe du nombre de collisions
|
||||
# (axisX, axisY) = nombresCollisions(ht)
|
||||
# plt.figure()
|
||||
# plt.plot(axisX, axisY, '-k')
|
||||
# plt.title('Nombre de collisions vs. indice table')
|
||||
# plt.grid(True)
|
||||
# plt.savefig("collisions.pdf")
|
||||
#
|
||||
# # Mot de valeur de hachage max
|
||||
(mot_max, hmax) = max_hash(fichier)
|
||||
print('valeur de hachage max: '+str(hmax)+' pour le mot: '+mot_max)
|
||||
TAILLE_TABLE = hmax+1
|
||||
init_ht(ht)
|
||||
load_ht(fichier, ht)
|
||||
print('Le mot '+mot_max+' doit être dans la liste : ', end='')
|
||||
ht[hmax].afficher()
|
||||
#
|
||||
# # Maintenant comparons wrt les tailles de ht.
|
||||
# stats_load(fichier)
|
||||
# stats_collisions(fichier)
|
||||
124
Formations/NSI/Bloc1/diubloc1-files-td3/libdiulistechainee.py
Normal file
@@ -0,0 +1,124 @@
|
||||
# ======================= Cellule ===========================================
|
||||
class Cellule:
|
||||
def __init__(self, val, suiv):
|
||||
self.val = val
|
||||
self.suiv = suiv
|
||||
|
||||
# ====================== ListeChainee ========================================
|
||||
class ListeChainee:
|
||||
""" Liste simplement chaînée non circulaire"""
|
||||
|
||||
def __init__(self):
|
||||
self.premier = None
|
||||
|
||||
def estVide(self):
|
||||
return self.premier == None
|
||||
|
||||
def nbElements(self):
|
||||
nb = 0
|
||||
elt = self.premier
|
||||
while elt:
|
||||
nb += 1
|
||||
elt = elt.suiv
|
||||
return nb
|
||||
|
||||
def iemeElement(self, indice):
|
||||
elt = self.premier
|
||||
for i in range(indice):
|
||||
elt = elt.suiv
|
||||
if elt == None:
|
||||
print("Erreur iemeElement : indice trop grand")
|
||||
return elt.val
|
||||
|
||||
def modifierIemeElement(self, indice, valElement):
|
||||
elt = self.premier
|
||||
for i in range(indice):
|
||||
elt = elt.suiv
|
||||
if elt == None:
|
||||
print("Erreur modifierIemeElement : indice trop grand")
|
||||
elt.val = valElement
|
||||
|
||||
def afficher(self):
|
||||
elt = self.premier
|
||||
while elt:
|
||||
print(elt.val, end=' ')
|
||||
elt = elt.suiv
|
||||
print()
|
||||
|
||||
def ajouterEnTete(self, valElement):
|
||||
elt = Cellule(valElement, self.premier)
|
||||
self.premier = elt
|
||||
|
||||
def insererDansListeTriee(self,cellule,valElement):
|
||||
celluleSuivante = cellule.suiv
|
||||
if celluleSuivante == None or celluleSuivante.val > valElement:
|
||||
elt = Cellule(valElement, celluleSuivante)
|
||||
cellule.suiv = elt
|
||||
else:
|
||||
self.insererDansListeTriee(celluleSuivante,valElement)
|
||||
|
||||
def ajouterDansListeTriee(self, valElement):
|
||||
if self.estVide():
|
||||
self.ajouterEnTete(valElement)
|
||||
else:
|
||||
if self.premier.val > valElement:
|
||||
self.ajouterEnTete(valElement)
|
||||
else:
|
||||
self.insererDansListeTriee(self.premier,valElement)
|
||||
|
||||
def supprimerTete(self):
|
||||
elt = self.premier
|
||||
self.premier = elt.suiv
|
||||
|
||||
def rechercheElement(self, valElement):
|
||||
elt = self.premier
|
||||
trouve = False
|
||||
pos = 0
|
||||
while elt and not trouve:
|
||||
if valElement == elt.val:
|
||||
trouve = True
|
||||
else:
|
||||
elt = elt.suiv
|
||||
pos += 1
|
||||
if trouve:
|
||||
return pos
|
||||
else:
|
||||
return -1
|
||||
|
||||
def chargerDepuisFichier(self,nomFichier):
|
||||
with open(nomFichier) as fichier:
|
||||
for ligne in fichier:
|
||||
self.insererDansListeTriee(ligne)
|
||||
|
||||
|
||||
# ========================== programme de test =====================================
|
||||
|
||||
# lc = ListeChainee()
|
||||
# print("Ajout en tete de 5 '2' 4 : ", end='')
|
||||
# lc.ajouterEnTete(5)
|
||||
# lc.ajouterEnTete("2")
|
||||
# lc.ajouterEnTete(4)
|
||||
# lc.afficher()
|
||||
#
|
||||
# print("Valeur de l'element a l'indice 1 : ", lc.iemeElement(1))
|
||||
#
|
||||
# print("Modification de l'element a l'indice 1 (1.6) : ", end='')
|
||||
# lc.modifierIemeElement(1, 1.6)
|
||||
# lc.afficher()
|
||||
#
|
||||
# print("Nombre d'elements : ", lc.nbElements())
|
||||
#
|
||||
# print("Suppression de l'element de tete : ", end='')
|
||||
# lc.supprimerTete()
|
||||
# lc.afficher()
|
||||
#
|
||||
# print("Recherche de la valeur 5 : ", lc.rechercheElement(5))
|
||||
# print("Recherche de la valeur 'coucou' : ", lc.rechercheElement("coucou"))
|
||||
#
|
||||
# lcmots = ListeChainee()
|
||||
# print("Ajout dans liste triee de 'abc' 'edf' 'b' 'a' : ", end='')
|
||||
# lcmots.ajouterDansListeTriee("abc")
|
||||
# lcmots.ajouterDansListeTriee("edf")
|
||||
# lcmots.ajouterDansListeTriee("b")
|
||||
# lcmots.ajouterDansListeTriee("a")
|
||||
# lcmots.afficher()
|
||||
110
Formations/NSI/Bloc1/diubloc1-files-td5/Conversions.ipynb
Normal file
@@ -0,0 +1,110 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 27,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def binaire2decimal(chaine):\n",
|
||||
" ans = 0\n",
|
||||
" for c in chaine:\n",
|
||||
" print(c)\n",
|
||||
" ans = ans*2+int(c)\n",
|
||||
" return ans"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"1\n",
|
||||
"0\n",
|
||||
"0\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"4"
|
||||
]
|
||||
},
|
||||
"execution_count": 29,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"binaire2decimal(\"100\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 47,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def decimal2binaire(nombre):\n",
|
||||
" binaire = []\n",
|
||||
" reste = nombre\n",
|
||||
" while reste:\n",
|
||||
" binaire.append(reste % 2)\n",
|
||||
" reste = reste // 2\n",
|
||||
" return binaire[::-1]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 48,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"[1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0]"
|
||||
]
|
||||
},
|
||||
"execution_count": 48,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"decimal2binaire(1234)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.1"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
40
Formations/NSI/Bloc1/diubloc1-files-td5/change_repr.py
Normal file
@@ -0,0 +1,40 @@
|
||||
#! /usr/bin/env python3
|
||||
"""
|
||||
python3 demo_test2.py
|
||||
"""
|
||||
__author__ = "Laure Gonnord"
|
||||
__copyright__ = "Univ Lyon1, 2019"
|
||||
|
||||
## fortement inspiré de http://sdz.tdct.org/sdz/du-decimal-au-binaire.html
|
||||
|
||||
CHIFFRES = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
NOMBRES = {c: n for (n, c) in enumerate(CHIFFRES)}
|
||||
|
||||
# Fonctions utilitaires
|
||||
def chiffre(n):
|
||||
return CHIFFRES[n]
|
||||
|
||||
def nombre(ch):
|
||||
"""ch= caractère qui désigne le nombre
|
||||
retourne le nombre associé"""
|
||||
return NOMBRES[ch]
|
||||
|
||||
chiffre(12) # 'C'
|
||||
nombre('C') # 12
|
||||
|
||||
# base b vers décimal
|
||||
def lire_repr(rep, b):
|
||||
nb_chiff = len(rep)
|
||||
somme = 0
|
||||
# TODO
|
||||
return somme
|
||||
|
||||
print(lire_repr('2A',16))
|
||||
|
||||
# représentation du nombre n en base b, retourne une chaîne
|
||||
# à chaque fois on ajoute à la fin de la chaîne.
|
||||
def repr_nombre(n, b):
|
||||
pass
|
||||
|
||||
print(repr_nombre(10, 2)) # 1010
|
||||
print(repr_nombre(42, 16)) # 2A
|
||||
21
Formations/NSI/Bloc1/diubloc1-files-td5/demo_repnombres.py
Normal file
@@ -0,0 +1,21 @@
|
||||
#! /usr/bin/env python3
|
||||
"""
|
||||
python3 demo_repnombres.py
|
||||
"""
|
||||
__author__ = "Laure Gonnord"
|
||||
__copyright__ = "Univ Lyon1, 2019"
|
||||
|
||||
# expérimentations autour de la représentation des nombres en python
|
||||
|
||||
x = bin(42)
|
||||
print(type(x)) # c'est une chaîne
|
||||
print(x)
|
||||
|
||||
y = hex(54)
|
||||
print(y)
|
||||
|
||||
z = 67
|
||||
|
||||
|
||||
# on peut utiliser le formattage python pour imprimer les rep.
|
||||
print("my num is 0x{0:02x}".format(z))
|
||||
16
Formations/NSI/Bloc1/diubloc1-files-td6/display_file.py
Normal file
@@ -0,0 +1,16 @@
|
||||
def display_file(name):
|
||||
with open(name, 'rb') as f:
|
||||
print("Voici les dix premiers caractères du fichier " +
|
||||
name + " :")
|
||||
for i in range(10):
|
||||
c = f.read(1)
|
||||
if len(c) == 0: # vrai si on est arrivé à la fin du fichier
|
||||
break
|
||||
print("Position " + str(i) + " : '" + c.decode('latin1') +
|
||||
"' (code ASCII = " + str(ord(c)) + ")")
|
||||
|
||||
|
||||
display_file('traitement-de-texte.odt')
|
||||
display_file('lyon1.png')
|
||||
display_file('display_file.py')
|
||||
display_file('donnees-2-colonnes.csv')
|
||||
@@ -0,0 +1,3 @@
|
||||
0, 10
|
||||
1, 12
|
||||
4, 15
|
||||
|
5
Formations/NSI/Bloc1/diubloc1-files-td6/donnees.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
1
|
||||
12.3
|
||||
43
|
||||
3
|
||||
10
|
||||
9
Formations/NSI/Bloc1/diubloc1-files-td6/ex_csvlib.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# cf https://docs.python.org/fr/3/library/csv.html
|
||||
|
||||
import csv
|
||||
|
||||
fieldnames = ['x', 'y']
|
||||
with open('donnees-2-colonnes.csv', newline='') as csvfile:
|
||||
reader = csv.DictReader(csvfile, fieldnames=fieldnames)
|
||||
for row in reader:
|
||||
print(row['x'], row['y'])
|
||||
BIN
Formations/NSI/Bloc1/diubloc1-files-td6/lyon1.jpg
Normal file
|
After Width: | Height: | Size: 253 KiB |
BIN
Formations/NSI/Bloc1/diubloc1-files-td6/lyon1.png
Normal file
|
After Width: | Height: | Size: 212 KiB |