1 changed files with 87 additions and 0 deletions
@ -0,0 +1,87 @@ |
|||||
|
#définition de la fonction |
||||
|
def reussite (joueur, action): |
||||
|
#établissement des variables |
||||
|
tentatives = 0 |
||||
|
réussites = 0 |
||||
|
#en ouvrant le fichier stats la commande va cherche une ligne avec le nom du joueur l'action et ajouter + 1 ) la variable tentatives chaque fois qu'elle la trouve puis regarder si le mot reussi est sur la même ligne si c'est le cas elle ajoutera + 1 à la variable réussite |
||||
|
with open("stats.txt", "r") as fichier: |
||||
|
for ligne in fichier: |
||||
|
if joueur.upper() + " " in ligne and action in ligne: |
||||
|
tentatives += 1 |
||||
|
if "tir-reussi" in ligne or "lancer-reu" in ligne: |
||||
|
réussites += 1 |
||||
|
return tentatives, réussites, |
||||
|
|
||||
|
#print(reussite("j4v", "tir")) |
||||
|
|
||||
|
def points (x, y): |
||||
|
#les coordonnées du centre gauche et droit et le rayon du cercle |
||||
|
centre_gauche = (0, 300) |
||||
|
centre_droit = (1000, 300) |
||||
|
rayon = 250 |
||||
|
#on vérifie si le point est dans le cercle gauche ou droit |
||||
|
dans_gauche = (x - centre_gauche[0])**2 + (y - centre_gauche[1])**2 <= rayon**2 and x <= 0 + rayon |
||||
|
dans_droit = (x - centre_droit[0])**2 + (y - centre_droit[1])**2 <= rayon**2 and x >= 1000 - rayon |
||||
|
#si c'est le cas on revoie 2 sinon on renvoie 3 |
||||
|
if dans_gauche or dans_droit: |
||||
|
return 2 |
||||
|
else: |
||||
|
return 3 |
||||
|
|
||||
|
#print(points(250, 300)) |
||||
|
|
||||
|
def totalpoints (joueur): |
||||
|
#on établie la variable des points totaux |
||||
|
total_points = 0 |
||||
|
with open("stats.txt", "r") as fichier: |
||||
|
for ligne in fichier: |
||||
|
element = ligne.split() |
||||
|
#on regarde dans chaque ligne si le nom du joueur choisit y est |
||||
|
if joueur.upper() + " " in ligne: |
||||
|
#si le nom est suivi de tir-reussi la commande regardera à l'aide de la fonction points si c'est un tir à 2 ou 3 point puis ajoutera en conséquence 2 ou 3 à la variable total_points |
||||
|
if element[1] == "tir-reussi": |
||||
|
x = int(element[2]) |
||||
|
y = int(element[3]) |
||||
|
total_points += points(x, y) |
||||
|
#si c'est un lancer franc la commande ajoutera 1 à la variablke total_points |
||||
|
elif element[1] == "lancer-reu": |
||||
|
total_points += 1 |
||||
|
return total_points |
||||
|
|
||||
|
#print(totalpoints("j1")) |
||||
|
|
||||
|
def rebondspasses (joueur): |
||||
|
with open("stats.txt", "r") as fichier: |
||||
|
rebond_pris = 0 |
||||
|
passe = 0 |
||||
|
for ligne in fichier: |
||||
|
if joueur.upper() + " " in ligne and ("rebondOff"or "rebondDef") in ligne: |
||||
|
rebond_pris += 1 |
||||
|
elif joueur.upper() + " " in ligne and "passe" in ligne: |
||||
|
passe += 1 |
||||
|
return rebond_pris, passe |
||||
|
|
||||
|
#print(rebondspasses("j1")) |
||||
|
|
||||
|
def manque (joueur): |
||||
|
with open("stats.txt", "r") as fichier: |
||||
|
#on établie la variable de perte de balle |
||||
|
perte_balle = 0 |
||||
|
for ligne in fichier: |
||||
|
#si le nom du joueur et un tir-manque apparait sur la même ligne la variable augemnte de 1 |
||||
|
if joueur.upper() + " " in ligne and "tir-manque" in ligne: |
||||
|
perte_balle += 1 |
||||
|
#de même pour un lancer raté |
||||
|
elif joueur.upper() + " " in ligne and "lancer-rat" in ligne: |
||||
|
perte_balle += 1 |
||||
|
return perte_balle |
||||
|
|
||||
|
#print(manque("j1")) |
||||
|
|
||||
|
def affichestats (joueur): |
||||
|
print(totalpoints(joueur)) |
||||
|
taux_reussite = reussite(joueur, "tir") |
||||
|
print(taux_reussite[1] / taux_reussite[0] * 100) |
||||
|
print(manque(joueur)) |
||||
|
|
||||
|
print(affichestats("j1")) |
Loading…
Reference in new issue