Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.lang.python > #3720
| From | Benoit Izac <use.reply.to@INVALID.ADDRESS> |
|---|---|
| Newsgroups | fr.comp.lang.python |
| Subject | Re: Sortir d 'une boucle while |
| Date | 2022-01-31 08:01 +0100 |
| Message-ID | <875yq09yod.fsf@izac.org> (permalink) |
| References | <zM6dnZ5wDbXEsGr8nZ2dnUU7_8zNnZ2d@giganews.com> |
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
Back to fr.comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Sortir d 'une boucle while Cyrion81 <nospam_thy.prog@orange.fr.invalid> - 2022-01-30 18:29 -0600 Re: Sortir d 'une boucle while Dominique <zzz@aol.com.invalid> - 2022-01-31 06:35 +0100 Re: Sortir d 'une boucle while Benoit Izac <use.reply.to@INVALID.ADDRESS> - 2022-01-31 08:01 +0100 Re: Sortir d 'une boucle while Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2022-01-31 09:27 +0100 Re: Sortir d 'une boucle while "Th.A.C" <aenleverraivac@free.fr.invalid> - 2022-01-31 23:25 +0100
csiph-web