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


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

Re: Création liste en ligne en .txt

Newsgroups fr.comp.lang.python
Subject Re: Création liste en ligne en .txt
From thomasdeshayes <nospam_t.deshayes2111@laposte.net.invalid>
References <kdadnUbx854BgijCnZ2dnUU798zNnZ2d@giganews.com> <87k0uir40q.fsf@izac.org>
Organization !No_Organization!
Message-ID <W4adnfT3mqd2vivCnZ2dnUU798zNnZ2d@giganews.com> (permalink)
Date 2020-11-19 01:51 -0600

Show all headers | View raw


Le mercredi 18 Novembre 2020 à 18:03 par Benoit Izac :
> Bonjour,
> 
> Le 18/11/2020 Í  14:20, ThomasDeshayes a écrit dans le
> message
> 
> 
>> Je souhaite réaliser le jeu du pendu avec une liste que j'ai
>> crée en
>> .txt, mais je rencontre un problème avec l'importation de la liste
>> (les mots sont en lignes et non en colonne), c'est-Í -dire que je
>> voudrai prendre un mot de la liste mais python me prend toutes la
>> ligne de la liste.
>> 
>> PS : les mots sont séparés uniquement par des points-virgules.
>> 
>> Pouvez-vous m'aider, s'il vous plait
>> 
>> 
> On devrait pouvoir mais tu as omis de nous montrer ton code.
> 
> --
> Benoit Izac
Oui, excusez moi, je vous envoie le code ci-dessous :

#Permet de choisir un mot dans le dossier
mot = [ ]
with open ("mot.txt","r") as doc :
    for l in doc :
        mot.append(l.rstrip("\n"))
motspendu = random.choice(mot)
#Nos différentes variables
lettres = [ ]
perdu = 0
gagne = False
corp_entier = ["O", "/", "|", "\", "/", "\"]
corp = [" ", " ", " ", " ", " ", " "]
while not gagne :
    gagne = True
    print (" +---+")
    print (" |      |")
    print (" |     {}".format (corp [0]))
    print (" |   {} {} {}".format (corp[1], corp[2], corp[3]))
    print (" |   {}    {}".format (corp[4], corp[5]))
    print (" |")
    for l in motspendu :
        if l in lettres :
            print (l, end = " ")
        else :
            gagne = False
            print ("_", end = " ")
    print ( )
    print ("Lettres déjà utilisées - ", end =" ")
    for l in lettres :
        print (l, end = " | ")
    print ( )
if perdu > 5 :
        print ("Vous avez perdu !")
        print ("Mot - { }".format (motspendu))
        break

    if gagne :
        print ("Vous avez gagne !")
        break

    joue = input ("Entrez une lettre : ")
    lettres.append (joue)

    if joue not in motspendu :
        corp [perdu] = corp_entier [perdu]
        perdu += 1

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


Thread

Création liste en ligne en .txt ThomasDeshayes <nospam_t.deshayes2111@laposte.net.invalid> - 2020-11-18 07:20 -0600
  Re: Création liste en ligne en .txt Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2020-11-18 18:03 +0100
    Re: Création liste en ligne en .txt thomasdeshayes <nospam_t.deshayes2111@laposte.net.invalid> - 2020-11-19 01:51 -0600
      Re: Création liste en ligne en .txt Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2020-11-19 16:14 +0100
  Re: Création liste en ligne en .txt thomasdeshayes <nospam_t.deshayes2111@laposte.net.invalid> - 2020-11-24 08:31 -0600

csiph-web