From b3721a511babbd9f517c7e43a53f10bdf70ed010 Mon Sep 17 00:00:00 2001 From: "tom.guerin" Date: Fri, 14 Nov 2025 14:17:17 +0100 Subject: [PATCH] Ajout du tp de python et regex --- sisr2/sisr/35-python/analog.py | 20 ++++++++++++++++++++ sisr2/sisr/35-python/exo.py | 14 ++++++++++++++ sisr2/sisr/35-python/exo1.py | 8 ++++++++ sisr2/sisr/35-python/exo2.py | 30 ++++++++++++++++++++++++++++++ sisr2/sisr/35-python/exo3.py | 3 +++ 5 files changed, 75 insertions(+) create mode 100644 sisr2/sisr/35-python/analog.py create mode 100644 sisr2/sisr/35-python/exo.py create mode 100644 sisr2/sisr/35-python/exo1.py create mode 100644 sisr2/sisr/35-python/exo2.py create mode 100644 sisr2/sisr/35-python/exo3.py diff --git a/sisr2/sisr/35-python/analog.py b/sisr2/sisr/35-python/analog.py new file mode 100644 index 0000000..95f8ac0 --- /dev/null +++ b/sisr2/sisr/35-python/analog.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 +import sys +import re +regexp = "^(\S+) (\S+) (\S+) \[([^]]+)\] \"(\w+) (\S+).*\" (\d+) (\S+)" +cpthost={} +for line in sys.stdin: # on lit sur l’entrée standard + line = line.rstrip () # on enleve le retour ligne + res = re.match (regexp, line) + if res: + (host, rfc931, user, date, request, url, status, byte) = res.groups() + host = res.group (1) + byte = res.group (8) + #print ('host : ', host, ' byte : ', byte) + if host in cpthost: + cpthost[host]++int(byte) + else: + cpthost[host]=int(byte) + +for host in cpthost.keys(): + print(host, " ",cpthost[host]) diff --git a/sisr2/sisr/35-python/exo.py b/sisr2/sisr/35-python/exo.py new file mode 100644 index 0000000..89ee7c1 --- /dev/null +++ b/sisr2/sisr/35-python/exo.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 + +chaine= str (input('saisir une chaine : ')) +tab = choisir.split(' ') +cptmot={} + +for mot in tab: + if mot in cptmot: + cptmot[mot]+=1 + else: + cptmot[mot]=1 + +for mot in cptmot.keys(): + print("mot:",mot,":"cptmot[mot]) diff --git a/sisr2/sisr/35-python/exo1.py b/sisr2/sisr/35-python/exo1.py new file mode 100644 index 0000000..c5ab197 --- /dev/null +++ b/sisr2/sisr/35-python/exo1.py @@ -0,0 +1,8 @@ +#!/usr/bin/python3 + +import math + +rayon = float(input("Entrez le rayon : ")) +perimetre = 2 * math.pi * rayon + +print("périmètre :", perimetre) diff --git a/sisr2/sisr/35-python/exo2.py b/sisr2/sisr/35-python/exo2.py new file mode 100644 index 0000000..0ff7545 --- /dev/null +++ b/sisr2/sisr/35-python/exo2.py @@ -0,0 +1,30 @@ +#!/usr/bin/python3 + +tableau = [] +min = 0 +max = 0 +cumul = 0 + +print("entrer 5 chiffres") +for i in range(5): + nombre = float(input(f"Chiffre {i+1} : ")) + tableau.append(nombre) + + +for l in tableau: + if l < min: + min = l + if l > max: + max = l + cumul = cumul + l + +for l +moyenne = cumul / 5 + + +for l in tableau: + print(tableau[i]) + +print("le plus petit:", min) +print("le plus grand:", max) +print("la moyenne", moyenne) diff --git a/sisr2/sisr/35-python/exo3.py b/sisr2/sisr/35-python/exo3.py new file mode 100644 index 0000000..7e3b26f --- /dev/null +++ b/sisr2/sisr/35-python/exo3.py @@ -0,0 +1,3 @@ +#!/usr/bin/python3 + +phrase=(input("entrez