Python
Résolu
diablange
Messages postés
69
Statut
Membre
-
Luxerails Messages postés 162 Statut Membre -
Luxerails Messages postés 162 Statut Membre -
Bonsoir,
j'aimerai savoir pourquoi il me met : syntaxerror, invalid syntax la ou il a mon 'else'? Et pourquoi quand je donne les bonnes coordonnées il me met quand même faux?
Merci d'avance.
______________________________________________________
< code >from random import randrange
print("\t\t\t\t=== LE JEU DE LA BATAILLE NAVALE ===\n\n")
########### Début ###############
choixMode = nombreEntre = False
choixRecommencer = True
while choixRecommencer == True: ####Si l'utilisateur a choisi oui
while choixMode < 1 or choixMode > 2: ####Si on a choisi aucun des deux modes
print("1.- Jouer")
print("2.- Sortir\n")
print("Votre choix ?")
choixMode = input()
choixMode = int(choixMode)
if choixMode == 1: #####jouer
x = randrange (1, 11) ####Nombre au hasard des abscisses
y = randrange (1, 11) ####Nombre au hasard des ordonnees
print("(",x,";",y ,")\n") ### savoir oordonnes du debut
e = int(x)
f = int(y)
a=int(input("entrez l'abscisse"))
b=int(input("entrez l'ordonnée"))
if a and b!= e and f: ### si différent
print("Dans l'eau!\n")
elif a and b==e and f: ### si pareil
print("Coulé!\n")
else a = e or a =f or b=e or b=f: ### si un coté commun
print ("en vue")
######### On demande s'il veut rejouer #########
print("Voulez-vous refaire une partie ? Tapez 0 pour non ou 1 pour oui :")
choixRecommencer = input()
choixRecommencer = bool(int(choixRecommencer))< code >
j'aimerai savoir pourquoi il me met : syntaxerror, invalid syntax la ou il a mon 'else'? Et pourquoi quand je donne les bonnes coordonnées il me met quand même faux?
Merci d'avance.
______________________________________________________
< code >from random import randrange
print("\t\t\t\t=== LE JEU DE LA BATAILLE NAVALE ===\n\n")
########### Début ###############
choixMode = nombreEntre = False
choixRecommencer = True
while choixRecommencer == True: ####Si l'utilisateur a choisi oui
while choixMode < 1 or choixMode > 2: ####Si on a choisi aucun des deux modes
print("1.- Jouer")
print("2.- Sortir\n")
print("Votre choix ?")
choixMode = input()
choixMode = int(choixMode)
if choixMode == 1: #####jouer
x = randrange (1, 11) ####Nombre au hasard des abscisses
y = randrange (1, 11) ####Nombre au hasard des ordonnees
print("(",x,";",y ,")\n") ### savoir oordonnes du debut
e = int(x)
f = int(y)
a=int(input("entrez l'abscisse"))
b=int(input("entrez l'ordonnée"))
if a and b!= e and f: ### si différent
print("Dans l'eau!\n")
elif a and b==e and f: ### si pareil
print("Coulé!\n")
else a = e or a =f or b=e or b=f: ### si un coté commun
print ("en vue")
######### On demande s'il veut rejouer #########
print("Voulez-vous refaire une partie ? Tapez 0 pour non ou 1 pour oui :")
choixRecommencer = input()
choixRecommencer = bool(int(choixRecommencer))< code >
4 réponses
Le manque d'indentation est dû au copié collé ou il n'y en a pas non plus dans ton code?
diablange
Messages postés
69
Statut
Membre
40
c'est dû à mon copier collé
Du Python sans indentation, c'est ... inexploitable :/
Merci de soumettre le code entre balises < code >
Merci de soumettre le code entre balises < code >
if a=b:
func()
from random import randrange
print("\t\t\t\t=== LE JEU DE LA BATAILLE NAVALE ===\n\n")
########### Début ###############
choixMode = nombreEntre = False
choixRecommencer = True
while choixRecommencer == True: ####Si l'utilisateur a choisi oui
while choixMode < 1 or choixMode > 2: ####Si on a choisi aucun des deux modes
print("1.- Jouer")
print("2.- Sortir\n")
print("Votre choix ?")
choixMode = input()
choixMode = int(choixMode)
if choixMode == 1: #####jouer
x = randrange (1, 11) ####Nombre au hasard des abscisses
y = randrange (1, 11) ####Nombre au hasard des ordonnees
print("(",x,";",y ,")\n") ### savoir oordonnes du debut
e = int(x)
f = int(y)
a=int(input("entrez l'abscisse"))
b=int(input("entrez l'ordonnée"))
if a and b!= e and f: ### si différent
print("Dans l'eau!\n")
elif a and b==e and f: ### si pareil
print("Coulé!\n")
except a = e or a =f or b=e or b=f: ### si un coté commun
print ("en vue")
######### On demande s'il veut rejouer #########
print("Voulez-vous refaire une partie ? Tapez 0 pour non ou 1 pour oui :")
choixRecommencer = input()
choixRecommencer = bool(int(choixRecommencer))