Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.python > #3371

Re: Pourquoi ca ne marche pas

From Benoit Izac <use.reply.to@INVALID.ADDRESS>
Newsgroups fr.comp.lang.python
Subject Re: Pourquoi ca ne marche pas
Date 2020-11-08 21:08 +0100
Message-ID <87lffbbohr.fsf@izac.org> (permalink)
References <KZWdnRtmc8WAsjXCnZ2dnUU798zNnZ2d@giganews.com>

Show all headers | View raw


Bonjour,

Le 08/11/2020 à 18:47, vdperic a écrit dans le message
<KZWdnRtmc8WAsjXCnZ2dnUU798zNnZ2d@giganews.com> :

> 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=20)
> L.place(x=20,y=10)
> E=Entry(fen,width=24)
> E.place(x=20,y=30)
> B=Button(fen,text="Valider",font='arial 9',width=20,command=verif)
> B.place(x=20,y=60)
> 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

Back to fr.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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