Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
45a25f53be | |||
189080c510 | |||
3e0abbf450 | |||
1fc1e5abb1 |
15
sio2/sisr/20-python/cptmot.py
Normal file
15
sio2/sisr/20-python/cptmot.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/lib/python3
|
||||||
|
|
||||||
|
phrase = input('Phrase : ')
|
||||||
|
tabmot = phrase.split(' ')
|
||||||
|
cptmot = {}
|
||||||
|
|
||||||
|
for mot in tabmot :
|
||||||
|
if mot in cptmot :
|
||||||
|
cptmot[mot] = cptmot[mot] + 1
|
||||||
|
else :
|
||||||
|
cptmot[mot] = 1
|
||||||
|
|
||||||
|
for key in cptmot.keys() :
|
||||||
|
print (key, " ", cptmot[key])
|
||||||
|
|
1
sio2/sisr/20-python/creatuser.txt
Normal file
1
sio2/sisr/20-python/creatuser.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
tdalle
|
9
sio2/sisr/20-python/ex1
Executable file
9
sio2/sisr/20-python/ex1
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
#1. Ecrire un programme python qui demande le rayon d’un cercle à l’utilisateur, calcule
|
||||||
|
#le périmètre (remarque: perimetre = 2 * 3.141592 * R) et affiche "Le périmètre vaut: "
|
||||||
|
|
||||||
|
R = int(input('Quel est le rayon du cercle ? '))
|
||||||
|
perimetre = 2 * 3.141592 * R
|
||||||
|
|
||||||
|
print('Le périmètre du cercle est ', perimetre)
|
34
sio2/sisr/20-python/ex2
Executable file
34
sio2/sisr/20-python/ex2
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
#Saisir un tableau de 5 chiffres en faisant une boucle
|
||||||
|
#◦ calculer le plus petit élément du tableau
|
||||||
|
#◦ calculer le plus grand élément du tableau
|
||||||
|
#◦ calculer la moyenne
|
||||||
|
#◦ afficher le tableau à l’aide d’une boucle
|
||||||
|
|
||||||
|
i=0
|
||||||
|
tab=[]
|
||||||
|
|
||||||
|
for i in range (5):
|
||||||
|
nombre = int(input('Donnez un chiffre à entrer dans le tableau : '))
|
||||||
|
tab.append(nombre)
|
||||||
|
|
||||||
|
moy = sum(tab)/len(tab)
|
||||||
|
|
||||||
|
maxi = tab[0]
|
||||||
|
for i in tab:
|
||||||
|
if i >= maxi:
|
||||||
|
maxi = i
|
||||||
|
|
||||||
|
|
||||||
|
mini = tab[0]
|
||||||
|
for i in tab:
|
||||||
|
if i <= mini:
|
||||||
|
mini = i
|
||||||
|
|
||||||
|
print('La moyenne des valeurs du tableau est: ',moy)
|
||||||
|
print('La plus grande valeur du tableau est: ',maxi)
|
||||||
|
print('La plus petite valeur du tableau est: ',mini)
|
||||||
|
|
||||||
|
for i in tab:
|
||||||
|
print(i)
|
8
sio2/sisr/20-python/ex3
Normal file
8
sio2/sisr/20-python/ex3
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
#3. Ecrire un programme qui saisisse une phrase au clavier et compte le nombre
|
||||||
|
#d’occurrences de chaque mot de la phrase. On affichera la liste avec chaque mot et
|
||||||
|
#le nombre d’occurrence
|
||||||
|
|
||||||
|
tabmot=[]
|
||||||
|
|
22
sio2/sisr/20-python/log.py
Normal file
22
sio2/sisr/20-python/log.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#/usr/bien/python3
|
||||||
|
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
cptip = {}
|
||||||
|
regexp = '^(\S+) (\S+) (\S+) \[([^]]+)\] "(\w+) (\S+).*" (\d+) (\S+)'
|
||||||
|
|
||||||
|
for line in sys.stdin :
|
||||||
|
line = line.rstrip ()
|
||||||
|
match = re.match (regexp, line)
|
||||||
|
if match :
|
||||||
|
print (match.group(1)," ",match.group(8))
|
||||||
|
ip = match.group(1)
|
||||||
|
vol = int(match.group(8))
|
||||||
|
if ip in cptip :
|
||||||
|
cptip[ip] = cptip[ip] + vol
|
||||||
|
else:
|
||||||
|
cptip[ip] = vol
|
||||||
|
|
||||||
|
for key in cptip.keys():
|
||||||
|
print(key, ":", cptip[key])
|
41
sio2/sisr/20-python/passusr.py
Executable file
41
sio2/sisr/20-python/passusr.py
Executable file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/lib/python3
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
nbarg = len(sys.argv)
|
||||||
|
if nbarg != 2:
|
||||||
|
print ("Nombre d'argument invalide")
|
||||||
|
exit (1)
|
||||||
|
filename = sys.argv[1]
|
||||||
|
try:
|
||||||
|
fh = open(filename, "r")
|
||||||
|
except:
|
||||||
|
print ("Fichier ", filename," inconnu")
|
||||||
|
exit (2)
|
||||||
|
else:
|
||||||
|
line = fh.readline ()
|
||||||
|
while line:
|
||||||
|
nouvline = line.rstrip()
|
||||||
|
login,nomlong = nouvline.split(':')
|
||||||
|
cmd = "sudo useradd -m -d /home/"+login+" -c \'"+ nomlong+"\' -s /bin/bash "+ login
|
||||||
|
res = os.system ("getent passwd "+login)
|
||||||
|
if res != 0:
|
||||||
|
passw = ["pwgen", "4","1"]
|
||||||
|
#passw = "pwgen 4 1"
|
||||||
|
os.system (cmd)
|
||||||
|
#mdp = str(os.system (passw))
|
||||||
|
#print (mdp)
|
||||||
|
mdp = subprocess.run(passw,capture_output=True)
|
||||||
|
mdp2 = mdp.stdout.decode("utf-8")
|
||||||
|
mdp3 = mdp2.rstrip()
|
||||||
|
print (mdp3)
|
||||||
|
ch3 = "echo "+login+":"+mdp3+"|sudo chpasswd"
|
||||||
|
print (ch3)
|
||||||
|
os.system (ch3)
|
||||||
|
os.system ("sudo echo "+login+":"+mdp3+" >> "+filename+".pwd")
|
||||||
|
else:
|
||||||
|
print ("Utilisateur "+login+" déjà éxistant")
|
||||||
|
os.system ("sudo userdel -r "+login)
|
||||||
|
line = fh.readline()
|
||||||
|
|
||||||
|
fh.close()
|
Loading…
x
Reference in New Issue
Block a user