Changement de type de variable

Fermé
Sweety83 Messages postés 17 Date d'inscription jeudi 16 avril 2015 Statut Membre Dernière intervention 15 mai 2015 - 9 mai 2015 à 20:18
dsy73 Messages postés 9252 Date d'inscription dimanche 22 août 2010 Statut Contributeur Dernière intervention 23 octobre 2020 - 15 mai 2015 à 21:06
Bonjour,

Actuellement élève terminale S option ISN j'ai un projet a mener pour le bac
j'ai créé mon programme sauf que je n'arrive pas a l'exécuter ... passant par une interface graphique avec tkinter mes int se transforment en str sauf que je dois faire des calcules avec mon programme.

Comment reconvertir des str en int ou faire un sorte que le type des variables ne change pas ?

Merci d'avance pour réponse .
Ceci est assez presser car mon examens se trouve dans une semaine seulement.
A voir également:

1 réponse

dsy73 Messages postés 9252 Date d'inscription dimanche 22 août 2010 Statut Contributeur Dernière intervention 23 octobre 2020 2 476
10 mai 2015 à 06:53
Salut
tu devrais mettre le code concerné (avec coloration syntaxique).
Pour la conversion de type : https://fr.wikiversity.org/wiki/Python/Les_types_de_base
0
Sweety83 Messages postés 17 Date d'inscription jeudi 16 avril 2015 Statut Membre Dernière intervention 15 mai 2015
Modifié par Sweety83 le 10/05/2015 à 17:47
voici mon programme:

code:

from Tkinter import *
from tkMessageBox import *

fenetre = Tk()
fenetre.title("connaitre le jour par rapport à une date")


def calculer():
if D>31 and M==1:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>31 and M==3:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>31 and M==5:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>31 and M==7:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>31 and M==8:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>31 and M==10:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>31 and M==12:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>30 and M==4:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>30 and M==6:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>30 and M==9:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>30 and M==11:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>29 and M==2:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif M>12 :
showwarning("attention","date non valide\nLe mois ne convient pas")
elif Y%4!=0 and D==29 and M==2:
showwarning("attention","date non valide\nL'année n'est pas bisextile")
elif Y%4==0 and Y%100==0 and Y%400!=0 and D==29 and M==2:
showwarning("attention","date non valide\nL'année n'est pas bisextile")
else:
if M>=3:
J=(((23*M)//9)+D+4+Y+(Y//4)-(Y//100)+(Y//400)-2)%7
if M<3:
Z=Y-1
J=(((23*M)//9)+D+4+Y+(Z//4)-(Z//100)+(Z//400))%7
if J==0:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un dimanche")
if J==1:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un lundi")
if J==2:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un mardi")
if J==3:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un mercredi")
if J==4:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un jeudi")
if J==5:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un vendredi")
if J==6:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un samedi")


D=IntVar()
Champ = Entry(fenetre, textvariable=D,bg='black', fg='white')
Champ.focus_set()
Champ.pack(side = LEFT, padx = 5, pady = 5)

M=IntVar()
Champ = Entry(fenetre, textvariable=M,bg='black', fg='white')
Champ.focus_set()
Champ.pack(side = LEFT, padx = 5, pady = 5)

Y=IntVar()
Champ = Entry(fenetre, textvariable=Y,bg='black', fg='white')
Champ.focus_set()
Champ.pack(side = LEFT, padx = 5, pady = 5)


bouton=Button(fenetre, text="calculer", command=calculer)
bouton.pack()

fenetre.mainloop()


ou faut-il que je rajoute la transformation pour qu'elle ai lieu correctement et que le programme puisse s'effectuer ?
0
dsy73 Messages postés 9252 Date d'inscription dimanche 22 août 2010 Statut Contributeur Dernière intervention 23 octobre 2020 2 476 > Sweety83 Messages postés 17 Date d'inscription jeudi 16 avril 2015 Statut Membre Dernière intervention 15 mai 2015
10 mai 2015 à 17:29
"(avec coloration syntaxique)"
0
Sweety83 Messages postés 17 Date d'inscription jeudi 16 avril 2015 Statut Membre Dernière intervention 15 mai 2015
10 mai 2015 à 17:47
comment sa ?
0
dsy73 Messages postés 9252 Date d'inscription dimanche 22 août 2010 Statut Contributeur Dernière intervention 23 octobre 2020 2 476 > Sweety83 Messages postés 17 Date d'inscription jeudi 16 avril 2015 Statut Membre Dernière intervention 15 mai 2015
10 mai 2015 à 19:14
C'est le dernier bouton dans l'éditeur du forum. Il permet de visualiser ton code correctement. Tel quel, il est trés difficile à lire.
0
Sweety83 Messages postés 17 Date d'inscription jeudi 16 avril 2015 Statut Membre Dernière intervention 15 mai 2015
10 mai 2015 à 19:34

from Tkinter import *
from tkMessageBox import *

fenetre = Tk()
fenetre.title("connaitre le jour par rapport à une date")


def calculer():
if D>31 and M==1:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>31 and M==3:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>31 and M==5:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>31 and M==7:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>31 and M==8:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>31 and M==10:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>31 and M==12:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>30 and M==4:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>30 and M==6:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>30 and M==9:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>30 and M==11:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif D>29 and M==2:
showwarning("attention","date non valide\nLe jour ne convient pas")
elif M>12 :
showwarning("attention","date non valide\nLe mois ne convient pas")
elif Y%4!=0 and D==29 and M==2:
showwarning("attention","date non valide\nL'année n'est pas bisextile")
elif Y%4==0 and Y%100==0 and Y%400!=0 and D==29 and M==2:
showwarning("attention","date non valide\nL'année n'est pas bisextile")
else:
if M>=3:
J=(((23*M)//9)+D+4+Y+(Y//4)-(Y//100)+(Y//400)-2)%7
if M<3:
Z=Y-1
J=(((23*M)//9)+D+4+Y+(Z//4)-(Z//100)+(Z//400))%7
if J==0:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un dimanche")
if J==1:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un lundi")
if J==2:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un mardi")
if J==3:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un mercredi")
if J==4:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un jeudi")
if J==5:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un vendredi")
if J==6:
showinfo("date","le ",D/1,"/",M/1,"/",Y/1," est un samedi")


D=IntVar()
Champ = Entry(fenetre, textvariable=D,bg='black', fg='white')
Champ.focus_set()
Champ.pack(side = LEFT, padx = 5, pady = 5)

M=IntVar()
Champ = Entry(fenetre, textvariable=M,bg='black', fg='white')
Champ.focus_set()
Champ.pack(side = LEFT, padx = 5, pady = 5)

Y=IntVar()
Champ = Entry(fenetre, textvariable=Y,bg='black', fg='white')
Champ.focus_set()
Champ.pack(side = LEFT, padx = 5, pady = 5)


bouton=Button(fenetre, text="calculer", command=calculer)
bouton.pack()

fenetre.mainloop()



comme sa c'est mieux ?
0