Ajout du tp de python et regex

This commit is contained in:
2025-11-14 14:17:17 +01:00
parent 522b01ef35
commit b3721a511b
5 changed files with 75 additions and 0 deletions

View File

@@ -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 lentré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])

View File

@@ -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])

View File

@@ -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)

View File

@@ -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)

View File

@@ -0,0 +1,3 @@
#!/usr/bin/python3
phrase=(input("entrez