Relancer programme python
Loxia
-
verexi1513 Messages postés 1 Statut Membre -
verexi1513 Messages postés 1 Statut Membre -
Bonjour, voici mon programme, je voudrais qu'il se relance si aucun des 'if' ne fonction donc après le 'else' SVP j'ai besoin d'aide
import random
voiture = ["P1", "P2", "P3"]
des = ["P1","P2", "P3"]
choix = ["garde", "change"]
P=[]
V=(random.choice(voiture))
D=(random.choice(des))
C=(random.choice(choix))
for i in range(P!=V and P!=D):
P=(random.choice(voiture))
if P!=V and P!=D:
print("Test")
if V==D and C=="garde":
print("Victoire")
print("Porte choisie : ", D)
print("Porte Présentateur", P)
print("Porte Voiture : ", V)
print("Votre choix : ", C)
if V==D and C=="change":
print("Dommage")
print("Porte choisie : ", D)
print("Porte Présentateur", P)
print("Porte Voiture : ", V)
print("Votre choix : ", C)
if V!=D and C=="change":
print("Victoire")
print("Porte choisie : ", D)
print("Porte Présentateur", P)
print("Porte Voiture : ", V)
print("Votre choix : ", C)
if V!=D and C=="garde":
print("Dommage")
print("Porte choisie : ", D)
print("Porte Présentateur", P)
print("Porte Voiture : ", V)
print("Votre choix : ", C)
else:
print("relance programme")
A voir également:
- Relancer programme python
- Programme demarrage windows - Guide
- Citizen code python avis - Accueil - Outils
- Relancer spooler impression - Guide
- Programme word gratuit - Guide
- Message programmé iphone - Guide
3 réponses
Bonjour,
Tu pourrais utiliser une boucle while,
import random
import time
voiture = ["P1", "P2", "P3"]
des = ["P1","P2", "P3"]
choix = ["garde", "change"]
while True:
P=[]
V=(random.choice(voiture))
D=(random.choice(des))
C=(random.choice(choix))
for i in range(P!=V and P!=D):
P=(random.choice(voiture))
if P!=V and P!=D:
print("Test")
if V==D and C=="garde":
print("Victoire")
print("Porte choisie : ", D)
print("Porte Présentateur", P)
print("Porte Voiture : ", V)
print("Votre choix : ", C)
if V==D and C=="change":
print("Dommage")
print("Porte choisie : ", D)
print("Porte Présentateur", P)
print("Porte Voiture : ", V)
print("Votre choix : ", C)
if V!=D and C=="change":
print("Victoire")
print("Porte choisie : ", D)
print("Porte Présentateur", P)
print("Porte Voiture : ", V)
print("Votre choix : ", C)
if V!=D and C=="garde":
print("Dommage")
print("Porte choisie : ", D)
print("Porte Présentateur", P)
print("Porte Voiture : ", V)
print("Votre choix : ", C)
else:
print("************relance programme")
time.sleep(2)
Cette boucle infinie recommence même si on ne passe pas par "relance programme".
Ceci ne recommence que si on passe par "relance programme":
import random
encore=True
while encore:
voiture = ["P1", "P2", "P3"]
des = ["P1","P2", "P3"]
choix = ["garde", "change"]
P=[]
V=(random.choice(voiture))
D=(random.choice(des))
C=(random.choice(choix))
for i in range(P!=V and P!=D):
P=(random.choice(voiture))
if P!=V and P!=D:
print("Test")
if V==D and C=="garde":
print("Victoire")
print("Porte choisie : ", D)
print("Porte Présentateur", P)
print("Porte Voiture : ", V)
print("Votre choix : ", C)
if V==D and C=="change":
print("Dommage")
print("Porte choisie : ", D)
print("Porte Présentateur", P)
print("Porte Voiture : ", V)
print("Votre choix : ", C)
if V!=D and C=="change":
print("Victoire")
print("Porte choisie : ", D)
print("Porte Présentateur", P)
print("Porte Voiture : ", V)
print("Votre choix : ", C)
if V!=D and C=="garde":
print("Dommage")
print("Porte choisie : ", D)
print("Porte Présentateur", P)
print("Porte Voiture : ", V)
print("Votre choix : ", C)
encore=False
else:
print("relance programme")