Recuperer la valeur d'une fonction

Résolu/Fermé
dan1ye Messages postés 7 Date d'inscription jeudi 31 juillet 2014 Statut Membre Dernière intervention 6 août 2014 - Modifié par dan1ye le 5/08/2014 à 16:06
 PacoFesk - 22 juil. 2022 à 18:44
Bonjour,
J'aimerai savoir comment je peux recuperer la valeur retournée d'une fonction, la stocker dans une variable afin de l'exploiter.
Voici le code de la fonction et je veux recuperer Cn et Cs pour un calcul


Matrix = [[0 for x in xrange(10)] for x in xrange(10)]
x=4 #Coordonnee en x egal ind_ic
y=4 #Coordonnee en y egal a p et ind_jc
r=2 #rayon de couverture
SN=0 #Difference entre Nord et Sud

def maj():
Matrix[4][2]=1 #West"
Matrix[4][4]=5 #Centre de matrice noeud"
Matrix[4][6]=3 #East"
Matrix[2][4]=2 #"Nord
Matrix[6][4]=4 #"South

def show():
for line in Matrix:
print line
return line

def nord():
global x
global y
global r
Cn=0
i=0
i=y-r
for somme in range(len(Matrix)):
if i <= (y+r):
Cn+=Matrix[2][i]
i+=1
return Cn

def south():
global x
global y
global r
Cs=0
i=0
i=y-r
for somme in range(len(Matrix)):
if i <= (y+r):
Cs+=Matrix[6][i]
i+=1
return Cs

maj()
show()
nord()
south()
SN=(int(Cn)-int(Cs))**2

Comment faire svp
Merci,


2 réponses

Utilisateur anonyme
5 août 2014 à 17:12
Imaginons une fonction simple

def function(a):
    return a


Pour récupérer le résultat dans une variable je fais ceci

variable = function(12)
15
variable = function(12) ?
c'est quoi le 12
0

pardon mais je ne comprend pas a quoi correspond le 12. + d'indications svp.

0