Ajout du tp de python et regex
This commit is contained in:
20
sisr2/sisr/35-python/analog.py
Normal file
20
sisr2/sisr/35-python/analog.py
Normal 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 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])
|
||||
14
sisr2/sisr/35-python/exo.py
Normal file
14
sisr2/sisr/35-python/exo.py
Normal 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])
|
||||
8
sisr2/sisr/35-python/exo1.py
Normal file
8
sisr2/sisr/35-python/exo1.py
Normal 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)
|
||||
30
sisr2/sisr/35-python/exo2.py
Normal file
30
sisr2/sisr/35-python/exo2.py
Normal 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)
|
||||
3
sisr2/sisr/35-python/exo3.py
Normal file
3
sisr2/sisr/35-python/exo3.py
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
phrase=(input("entrez
|
||||
Reference in New Issue
Block a user