Deutsch   English   Français   Italiano  
<875yq09yod.fsf@izac.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!pasdenom.info!news.izac.org!reader
From: Benoit Izac <use.reply.to@INVALID.ADDRESS>
Newsgroups: fr.comp.lang.python
Subject: Re: Sortir d 'une boucle while
Date: Mon, 31 Jan 2022 08:01:06 +0100
Message-ID: <875yq09yod.fsf@izac.org>
References: <zM6dnZ5wDbXEsGr8nZ2dnUU7_8zNnZ2d@giganews.com>
Reply-To: benoit.izac@free.fr
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: keg.izac.org;
	logging-data="1173895"; mail-complaints-to="usenet@izac.org"
Bytes: 2342
Lines: 57

Bonjour,

Le 31/01/2022 à 01:29, Cyrion a écrit dans le message
<zM6dnZ5wDbXEsGr8nZ2dnUU7_8zNnZ2d@giganews.com> :

> Je débute en python et j’ai voulu faire un programme qui ajoute un
> élément dans une liste, qui peut afficher la liste ainsi que quitte le
> programme. Je n’arrive pas a quitter le programme Merci de votre aide
>
> choix =""
> liste_elements = []
> liste_choix=[1,2,3,4,5]
> while True:
> #menu choix affiché
>     choix =""
>     print( )
>     print("--------------------------------")
>     print("Choisissez parmi les 3options suivantes :")
>     print("1: Ajouter un élément à la liste.")
>     print("2: Afficher la liste.")
>     print("3: Quitter.")
>
> #test entrée est bien un chiffre
>     while True:
>         try:
>             choix=int(input("Votre choix ?"))
>             break
>         except ValueError :
>             print("Erreur, votre choix doit etre un nombre!")
>
> #test du nombre entré et option exécutée

Le problème est là :

>     while choix in liste_choix:

À quoi sert le while ici ?

>         if choix == 1 :
>             print("Choix 1, ajouter un élément")
>             ajouter=input("Votre ajout ?")
>             liste_elements.append(ajouter)
>             break
>
>         if choix == 2 :
>             print("Choix 2, Afficher la liste")
>             print(liste_elements)
>             break
>
>         if choix == 3
>             print("Choix 3 , Quitter")
>             break
>
>     Je cherche a quitter le premier while ( le menu )uniquement si j ai fini
> toutes les opérarions et pressant la touche 3

-- 
Benoit Izac