Code calcul bac
Itachi-Uchiha
-
Itachi-Uchiha -
Itachi-Uchiha -
Bonjour,
j'ai réaliser un programme pour calculer la note du BAC mais celui-ci plante à la derniere étape (fonction calcul_note):
j'ai réaliser un programme pour calculer la note du BAC mais celui-ci plante à la derniere étape (fonction calcul_note):
from Tkinter import *
import tkMessageBox
window = Tk()
note = IntVar()
bac = StringVar()
numero = 0
notes = []
def choisir_bac():
global matieres, coeffs, notes, app
global question, saisie
bac_var = bac.get()
if bac_var == "S":
matieres = ['Maths','PC','LV1', 'Fr_Ecrit', 'Fr_Oral', 'HG', \
'SI', 'ISN', 'LV2', 'Philo', 'EPS', 'TPE']
coeffs = {'Maths':7, 'PC':6,'LV1':3, 'Fr_Ecrit':2, 'Fr_Oral':2, \
'HG':3, 'SI':6, 'ISN':2, 'LV2':2, 'Philo':3, 'EPS':2, \
'TPE':2}
elif bac_var == "ES":
matieres = ['Maths','Sciences','LV1', 'Fr_Ecrit', 'Fr_Oral', 'HG', \
'Sc.Eco', 'Sc.Pol.Sociale', 'LV2', 'Philo', 'EPS', 'TPE']
coeffs = {'Maths':5, 'Sciences':2,'LV1':3, 'Fr_Ecrit':2, 'Fr_Oral':2, \
'HG':5, 'SC.Eco':7, 'Sc.Pol.Sociale':4, 'LV2':2, 'Philo':4, \
'EPS':2, 'TPE':2}
app.destroy()
app = Frame(window)
app.pack()
question = Label(app, text = "Entrez votre note de " + matieres[numero])
question.pack()
saisie = Entry(app, textvariable = note, width = 10)
saisie.pack()
saisie.delete(0, END)
saisie.focus()
bouton_ok = Button(app, text = "OK", command = ajoute_note)
bouton_ok.pack(side = BOTTOM)
def ajout_notes():
global numero
# Validation
if 0 <= note.get() <= 20:
notes.append(note.get())
else:
saisie.delete(0, END)
tkMessageBox.showwarning("Erreur", "Entrez une note de 0 à 20")
return
if len(notes) < len(matieres):
numero += 1
saisie.delete(0, END)
question.config(text = "Entrez votre note de " + matieres[numero])
else:
bouton_ok = Button(app, text = "OK", command = calcul_note)
bouton_ok.pack(side = BOTTOM)
def calcul_note():
m = 0
for i in len(notes):
m = m + notes[i] * coeffs[i]
m = m / len(notes)
app.destroy()
app = Frame(window)
app.pack()
resultat["text"] = "Voici votre note: {0]".format(m)
bouton_fin = Button(app, text = "Quitter", command = window.destroy)
bouton_fin.pack(side = BOTTOM)
app = Frame(window)
app.pack()
intro = Label(app, text = "Ce programme va vous permettre \
de calculer votre resultat au BAC ")
intro.pack()
choix = Label(app, text = "Quel bac avez vous passé ?")
choix.pack()
bac_S = Radiobutton(app, text="S", variable = bac, value="S")
bac_ES = Radiobutton(app, text="ES", variable = bac, value="ES")
bac_S.pack()
bac_ES.pack()
bac.set('S') # Initialisation
bouton_ok = Button(app, text = "OK", command = choisir_bac)
bouton_ok.pack(side = BOTTOM)
window.mainloop()
A voir également:
- Code calcul bac
- Code ascii - Guide
- Code puk bloqué - Guide
- Comment déverrouiller un téléphone quand on a oublié le code - Guide
- Code activation windows 10 - Guide
- Calcul moyenne excel - Guide
2 réponses
Bonjour,
Dans la fonction "ajout_notes()" la liste notes[] n'est pas déclarée global.
Je suppose que ta fonction calcul_note() plante car du coup fait une une division par 0
Dans la fonction "ajout_notes()" la liste notes[] n'est pas déclarée global.
Je suppose que ta fonction calcul_note() plante car du coup fait une une division par 0
Effectivement...
En revanche to for est faux.
for i in len(notes):
Pour récupérer les index tu dois faire for i in range(len(notes)):
Egalement, si je regarde un peu plus haut, coeff est un dictionnaire et les dictionnaires ne sont pas ordonnés comme les listes. Leurs unique index sont ceux qui sont défini : "Math, PC, LV1, ..."
En revanche to for est faux.
for i in len(notes):
Pour récupérer les index tu dois faire for i in range(len(notes)):
Egalement, si je regarde un peu plus haut, coeff est un dictionnaire et les dictionnaires ne sont pas ordonnés comme les listes. Leurs unique index sont ceux qui sont défini : "Math, PC, LV1, ..."
Regarde ce code et teste le psk je vois pas l'erreur et tu cerneras mieux mon problème je pense:
from Tkinter import *
import tkMessageBox
window = Tk()
c = Canvas(window)
c.pack()
# image
fond = PhotoImage(file="forme.gif")
#image de fond
c.create_image(0,0, image=fond)
note = IntVar()
bac = StringVar()
numero = 0
notes = []
def choix_bac():
global matieres, coeffs, app, question, saisie
bac_var = bac.get()
if bac_var == "S":
matieres = ['Maths','PC','LV1', 'Fr_Ecrit', 'Fr_Oral', 'HG', \
'SI', 'ISN', 'LV2', 'Philo', 'EPS', 'TPE']
coeffs = [7, 6, 3, 2, 2, 3, 6, 2, 2, 3, 2, 2]
elif bac_var == "ES":
matieres = ['Maths','Sciences','LV1', 'Fr_Ecrit', 'Fr_Oral', 'HG', \
'Sc.Eco', 'Sc.Pol.Sociale', 'LV2', 'Philo', 'EPS', 'TPE']
coeffs = [5, 2,3, 2, 2, 5, 7, 4, 2, 4, 2, 2]
app.destroy()
app = Frame(window)
app.pack()
question = Label(app, text = "Entrez votre note de " + matieres[numero])
question.pack()
saisie = Entry(app, textvariable = note, width = 10)
saisie.pack()
saisie.delete(0, END)
saisie.focus()
bouton_ok = Button(app, text = "OK", command = ajout_notes)
bouton_ok.pack(side = BOTTOM)
def ajout_notes():
global numero
# Validation
if 0 <= note.get() <= 20:
notes.append(note.get())
else:
saisie.delete(0, END)
tkMessageBox.showwarning("Erreur", "Entrez une note de 0 à 20")
return
if len(notes) < len(matieres):
numero += 1
saisie.delete(0, END)
question.config(text = "Entrez votre note de " + matieres[numero])
else:
bouton_ok = Button(app, text = "OK", command = calcul_note)
bouton_ok.pack(side = BOTTOM)
def calcul_note():
m = 0
for i in range(len(notes)):
m = m + notes[i] * coeffs[i]
m = m / len(notes)
app = Frame(window)
app.pack()
resultat = Label(app, text = "Voici votre note:{0}".format(m))
resultat.pack()
bouton_fin = Button(app, text = "Quitter", command = window.destroy)
bouton_fin.pack(side = BOTTOM)
app = Frame(window)
app.pack()
intro = Label(app, text = "Ce programme va vous permettre \
de calculer votre resultat au BAC ")
intro.pack()
choix = Label(app, text = "Quel bac avez vous passé ?")
choix.pack()
bac_S = Radiobutton(app, text="S", variable = bac, value="S")
bac_ES = Radiobutton(app, text="ES", variable = bac, value="ES")
bac_S.pack()
bac_ES.pack()
bac.set('S') # Initialisation
bouton_ok = Button(app, text = "OK", command = choix_bac)
bouton_ok.pack(side = BOTTOM)
window.mainloop()