Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.lang.python > #3372
| Newsgroups | fr.comp.lang.python |
|---|---|
| Subject | Re: Pourquoi ca ne marche pas |
| From | vdperic <nospam_vdperic@yahoo.fr.invalid> |
| References | <KZWdnRtmc8WAsjXCnZ2dnUU798zNnZ2d@giganews.com> <87lffbbohr.fsf@izac.org> |
| Organization | !No_Organization! |
| Message-ID | <5e2dndzT_a8HGDTCnZ2dnUU798zNnZ2d@giganews.com> (permalink) |
| Date | 2020-11-09 12:08 -0600 |
Le dimanche 08 Novembre 2020 à 21:08 par Benoit Izac :
> Bonjour,
>
> Le 08/11/2020 Í 18:47, vdperic a écrit dans le message
>
>
>> Je commence Í m'intéresser Í Python. Je suis
>> le livre Apprendre la
>> programmation par le jeu. Pourquoi ceci fonctionne
>>
>> from tkinter import *
>> import random
>>
>> def melangemot(mot) :
>> melange = mot
>> for i in range(len(mot)) :
>> a = random.randint(0,len(mot)-1)
>> b = random.randint(0,len(mot)-1)
>> new = ""
>> for j in range(len(melange)) :
>> if j==a :
>> new = new + melange[b]
>> elif j==b :
>> new = new + melange[a]
>> else :
>> new = new + melange[j]
>> melange = new
>> return melange
>>
>> def verif():
>> if E.get().upper() == m :
>> L.config(text="Gagné !")
>> else :
>> B.config(text="Non, réessayer ?")
>>
>> fen = Tk()
>> fen.geometry("200x100")
>> fen.title("Mots mélangés")
>>
>> m="Maison"
>>
>>
>> L=Label(fen,text=melangemot(m),width )
>> L.place(x ,y)
>> E=Entry(fen,width$)
>> E.place(x ,y0)
>> B=Button(fen,text="Valider",font='arial 9',width ,command=verif)
>> B.place(x ,y`)
>> B.focus()
>> fen.mainloop()
>>
>>
> Pour moi, ça ne peut pas fonctionner : vu que tu compares
> une chaͮne que
> tu mets en majuscule Í 'Maison', personne ne gagnera
> jamais… Il faut un
> upper() (ou lower()) de chaque cÍ´té pour que ça
> fonctionne.
>
>> mais quand je mets
>> m=input("Choisissez un mot:")
>> ça ne marche plus.
>>
>>
> Boule de cristal HS. Tu mets ça o͹ ? Qu'est ce
> qui ne marche pas ?
>
>> Pouvez-vous m'expliquer ? Je vous en remercice
>>
>>
> input() attend quelque chose sur l'entrée standard ; en
> général le
> terminal. Donc si tu lances ça depuis autre chose qu'un terminal et que
> rien n'arrive sur l'entrée standard, ton programme reste bloqué
> après la
> création de la fenêtre. C'est peut-être ça
> «Â ne marche plus »Â ?
>
> PSÂ : il y a plus élégant pour mélanger ta
> chaÍ®ne de caractère :
>
> def melanger(mot):
> return ''.join(random.sample(mot, len(mot)))
>
> --
> Benoit Izac
En fait je vais réexpliquer:
Quand j'entre moi-même dans le programme le mot "Maison" (m="MAISON), ça
fonctionne bien !
Par contre quand je demande d'entrer un mot avec INPUT, ça ne marche plus. Le
programme reste bloqué et la fenêtre ne se crée pas.
C'est bizarre parce que si je demande print (m), le programme met bien le mot
choisi par l'utilisateur !
Merci déjà pour le mélange de caractères. C'est nettement plus court
Back to fr.comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Pourquoi ca ne marche pas vdperic <nospam_vdperic@yahoo.fr.invalid> - 2020-11-08 11:47 -0600
Re: Pourquoi ca ne marche pas Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2020-11-08 21:08 +0100
Re: Pourquoi ca ne marche pas vdperic <nospam_vdperic@yahoo.fr.invalid> - 2020-11-09 12:08 -0600
Re: Pourquoi ca ne marche pas Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2020-11-09 19:58 +0100
Re: Pourquoi ca ne marche pas vdperic <nospam_vdperic@yahoo.fr.invalid> - 2020-11-10 04:08 -0600
Re: Pourquoi ca ne marche pas Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2020-11-10 13:34 +0100
csiph-web