Bonjours j'aurai besoin d'aide pour traduire mon codage .
.gabriel.
Messages postés
3
Statut
Membre
-
.gabriel. Messages postés 3 Statut Membre -
.gabriel. Messages postés 3 Statut Membre -
bonjour a tout .
j'ai fait mon programme en java mais je vous le même en phyton mais comme je suis débutant j'ai pas trop réussi alors si vous pouvez m'aider .je vous remercie d'avance .
mon java :
( si vous voulez le voir en marche )
https://repl.it/repls/JaggedHelplessLevel
en pyton ( pyzo plus précisément )( j'ai mi une capture d'écran)
https://img-19.ccm2.net/dvWRI6sOUZV9yWTpeSAI61iE8a0=/5878f98f3dc6446a885c667510641ccf/tmp/Phyton_pyzo.PNG
ca fait pas du tout se que je voulez de basse ca depasse de ma matrice ca beug si vous pouvez m'aider
si vous vouler plus d informasion dit moi .
j'ai fait de mon mieux pour le code
codialement gabriel
j'ai fait mon programme en java mais je vous le même en phyton mais comme je suis débutant j'ai pas trop réussi alors si vous pouvez m'aider .je vous remercie d'avance .
mon java :
( si vous voulez le voir en marche )
https://repl.it/repls/JaggedHelplessLevel
import java.util.Random;
public class Main {
public static void main(String[] args) {
int [][] planche = new int[10][10];
for (int i = 0; i < planche.length ; i++) {
for (int j = 0; j < planche[0].length; j++) {
planche[i][j] = 0;
}
}
remplissageBat(planche,3);
String str="--";
for (int i = 0; i < planche.length ; i++) {
str+="-"+i+"-";
}
str+="\n";
for (int i = 0; i < planche.length ; i++) {
str+=i+"-";
for (int j = 0; j < planche[0].length ; j++) {
str+="|"+planche[i][j]+"|";
}
str+="\n";
}
System.out.println(str);
}
public static int[][] remplissageBat(int [][] planche, int tailleBateau){
int orientation = new Random().nextInt(2);//random entre 0 et 1
int x = new Random().nextInt(planche.length);//random entre 0 et taille tableau en longueur
int y = new Random().nextInt(planche.length);//random entre 0 et taille tableau en largeur
if(x+tailleBateau>=planche.length && orientation==0){
x= x - (x+tailleBateau-planche.length);
}else if(y+tailleBateau>=planche[0].length && orientation==1){
y= y - (y+tailleBateau-planche[0].length);
}
if (orientation == 0) {
for (int i = 0; i < tailleBateau ; i++) {
planche[x+i][y] = 1;
}
}else{
for (int i = 0; i < tailleBateau ; i++) {
planche[x][y+i] = 1;
}
}
return planche;
}
}
en pyton ( pyzo plus précisément )( j'ai mi une capture d'écran)
https://img-19.ccm2.net/dvWRI6sOUZV9yWTpeSAI61iE8a0=/5878f98f3dc6446a885c667510641ccf/tmp/Phyton_pyzo.PNG
import random
import numpy as np
planche= np.full ((10,10),0)
l=9
b=3
x = random.randrange(1,10,1)
y = random.randrange(1,10,1)
planche[x,y]=1
#pour un bateau de 3
choix=random.randrange(1,4)
#voir si ca depace pas du tableux ( cela marche pas )
#def renplicage (planche,x,y,l,b):
# tl=False
# if ((x+b-1)>l):
# tl=True
# elif((y+b-1)>l):
# tl=True
#else:
# for i in range b
# tl=False
#return(tl)
#verificasion
if (choix==1):
planche[x,y-1]=1
planche[x,y-2]=1
elif (choix==2): #double egal pour verifier l'égalité
planche[x-1,y]=1
planche[x-2,y]=1
elif (choix==3): #double egal pour verifier l'égalité
planche[x,y+1]=1
planche[x,y+2]=1
elif (choix==4): #double egal pour verifier l'égalité
planche[x+1,y]=1
planche[x+2,y]=1
elif(y==10):
planche[x,y-1]=1
planche[x,y-2]=1
print (planche)
ca fait pas du tout se que je voulez de basse ca depasse de ma matrice ca beug si vous pouvez m'aider
si vous vouler plus d informasion dit moi .
j'ai fait de mon mieux pour le code
codialement gabriel
1 réponse
-
yg_be Messages postés 23437 Date d'inscription Statut Contributeur Dernière intervention Ambassadeur 1 588
bonjour,
si tu veux traduire du java en python, je propose que tu commences par mettre le code java comme commentaire en python, puis de créer les instructions python correspondantes, chaque fois en dessous des commentaires.
pour le moment, je ne vois pas du tout la correspondance entre le code python et le code java.