Browse Source

Sujet 1, calcul de notes

master
maxence.aubailly 4 weeks ago
parent
commit
d53be02264
  1. 52
      Projets_note.py

52
Projets_note.py

@ -2,6 +2,7 @@ import tkinter as tk
# Configuration de la fenêtre # Configuration de la fenêtre
screen = tk.Tk() screen = tk.Tk()
screen.title("Calcul de notes")
screen.minsize(300, 300) screen.minsize(300, 300)
screen.maxsize(300, 300) screen.maxsize(300, 300)
@ -9,14 +10,14 @@ lst_nombre = []
# Différents textes présents (ou non) sur la page # Différents textes présents (ou non) sur la page
#Zone d'entrée pour les nombres #Zone d'entrée pour les nombres
welcome_txt = tk.Label(text="Veuillez entrer des nombres, pour connaitre \n la note la plus basse, la plus haute et la moyenne !") welcome_txt = tk.Label(text="Veuillez entrer des nombres, pour connaitre \n la note la plus basse, la plus haute et la moyenne ! \n Penser à bien vérifier vos nombre avant le calcul !")
welcome_txt.place(relx=0.5, y=70, anchor="center") welcome_txt.place(relx=0.5, y=70, anchor="center")
zone_texte = tk.Entry(width = 20) zone_texte = tk.Entry(width = 20)
zone_texte.place(relx=0.5, rely=0.5, anchor="center") zone_texte.place(relx=0.5, rely=0.5, anchor="center")
warning = tk.Label(text="") warning = tk.Label(text="")
warning.place(relx=0.5, rely=0.3, anchor="center") warning.place(relx=0.5, rely=0.4, anchor="center")
txt_note_min = tk.Label(text="") txt_note_min = tk.Label(text="")
txt_note_min.place(x=0, y=10) txt_note_min.place(x=0, y=10)
@ -42,27 +43,37 @@ def Verif():
lst_nombre.append(nombre) lst_nombre.append(nombre)
warning.config(text="") warning.config(text="")
except ValueError: except ValueError:
warning.config(text="Non") warning.config(text="Invalide")
print("Dommage !")
# Calcule la note max, min et la moyenne # Calcule la note max, min et la moyenne
def Calcul(): def Calcul():
global lst_nombre global lst_nombre
total = 0 try:
nombre_notes = 0 total = 0
print(lst_nombre) nombre_notes = 0
lst_nombre.sort() print(lst_nombre)
print(lst_nombre) lst_nombre.sort()
note_min = lst_nombre[0] print(lst_nombre)
note_max = lst_nombre[-1] note_min = lst_nombre[0]
for i in range(len(lst_nombre)): note_max = lst_nombre[-1]
total += lst_nombre[i] for i in range(len(lst_nombre)):
nombre_notes += 1 total += lst_nombre[i]
moyenne = total/nombre_notes nombre_notes += 1
moyenne = round(moyenne, 1) moyenne = total/nombre_notes
txt_note_min.config(text=f"Note la plus basse : {note_min}") moyenne = round(moyenne, 1)
txt_note_max.config(text=f"Note la plus haute : {note_max}") txt_note_min.config(text=f"Note la plus basse : {note_min}")
txt_moyenne.config(text=f"Moyenne du groupe : {moyenne}") txt_note_max.config(text=f"Note la plus haute : {note_max}")
txt_moyenne.config(text=f"Moyenne du groupe : {moyenne}")
except IndexError:
txt_note_min.config(text="")
txt_note_max.config(text="")
txt_moyenne.config(text="")
# Effacer les valeurs de la liste
def Effacer():
global lst_nombre
lst_nombre = []
# Différents bouton qui renvoie aux deux fonctions # Différents bouton qui renvoie aux deux fonctions
@ -72,4 +83,7 @@ bouton_verif.place(relx=0.5, rely=0.7, anchor="center")
bouton_calcul = tk.Button(width = 8, height = 3, text = "Calcul", command=Calcul) bouton_calcul = tk.Button(width = 8, height = 3, text = "Calcul", command=Calcul)
bouton_calcul.place(relx=0.7, rely=0.8,) bouton_calcul.place(relx=0.7, rely=0.8,)
bouton_calcul = tk.Button(width = 8, height = 3, text = "Effacer", command=Effacer)
bouton_calcul.place(x=22, rely=0.8,)
screen.mainloop() screen.mainloop()
Loading…
Cancel
Save