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

Ryan_Kafan Messages postés 1 Statut Membre -  
dachiasse Messages postés 1932 Statut Membre -
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

1 réponse

  1. dachiasse Messages postés 1932 Statut Membre 153
     
    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