Récupérer une variable d'une fonction dans une autre fonction.

Fermé
Ryan_Kafan Messages postés 1 Date d'inscription dimanche 4 avril 2021 Statut Membre Dernière intervention 4 avril 2021 - 4 avril 2021 à 01:24
dachiasse Messages postés 1709 Date d'inscription samedi 12 septembre 2020 Statut Membre Dernière intervention 13 mai 2021 - 4 avril 2021 à 01:32
Def t5():
svt = 33
chimie = 33.5
total1 = svt + chimie

Def t6():
maths = 18
histoire = 9.5
total2 = maths + chimie

Def t7():
total3 = total1 + total2

Comment je peux récupérer total1 de t5() et total2 de t6() pour effectuer l'opération dans t7()?
Merci
A voir également:

1 réponse

dachiasse Messages postés 1709 Date d'inscription samedi 12 septembre 2020 Statut Membre Dernière intervention 13 mai 2021 148
4 avril 2021 à 01:32
Salut,

Par un simple return, ça sert à cela.

def t5():
    svt = 33
    chimie = 33.5
    return svt + chimie

def t6():
    maths = 18
    histoire = 9.5 # peut mieux faire :D
    return maths + histoire

def t7(total_param1, total_param2)
    return total_param1 + total_param2

total1 = t5()
total2 = t6()

total3 = t7(total1, total2)

#si tu veux afficher le résultat :
print(f"Le total des notes est : {total3}")
0