Comment faire un retour automatique au menu dans un menu en temi

xunil2003 Messages postés 765 Date d'inscription   Statut Membre Dernière intervention   -  
dsy73 Messages postés 9252 Date d'inscription   Statut Contributeur Dernière intervention   -
Bonjour,

j'ai fait ce menu pour le terminal :
#!/usr/bin/python
print (30 * '-')
print (" - M E N U")
print (30 * '-')
print ("1. Sauvegarde")
print ("2. Restauration")
print ("3. Reboot server")
print (30 * '-')

choice = raw_input('Enter votre choix [1-3] : ')

choice = int(choice)

if choice == 1:
print ("Sauvegarde")
elif choice == 2:
print ("Restauration")
elif choice == 3:
print ("Reboot server...")
else: ## default ##
print ("Erreur saissi invalide ")

Je voudrais savoir comment faire un retour automatique au menu ?

Merci
A voir également:

3 réponses

ElementW Messages postés 4814 Date d'inscription   Statut Contributeur Dernière intervention   1 223
 
'lut, encadre tout ton code de menu dans un
while true:
.
0
xunil2003 Messages postés 765 Date d'inscription   Statut Membre Dernière intervention   14
 
Bonjour

Voilà c'est bon, j'ai fait comme ceci :
#!/usr/local/bin/python
# -*- coding:utf-8 -*-

def un():
print "1 - un"

def deux():
print "2 - deux"

def trois():
print "3 - trois"

def quatre():
print "4 - quatre\n Quitter"
quit()

while True:
print (30 * '-')
print (" M E N U")
print (30 * '-')
print "1) Sauvegarde"
print "2) Restauration"
print "3) Reboot server"
print "4) Quitter"
print (30 * '-')
print
choix = input('Veuillez indiquer votre choix [1-4] : ')
print choix
if choix == 1:
un()
elif choix == 2:
deux()
elif choix == 3:
trois()
elif choix == 4:
quatre()
else: ## default ##
print ("Erreur saissi invalide ")


Merci.
0
dsy73 Messages postés 9252 Date d'inscription   Statut Contributeur Dernière intervention   2 485
 
Je suppose que tu veux lire un seul caractère en entrée :
https://pypi.org/project/readchar/
0