Home > Net >  Python3 instruction assert with condition
Python3 instruction assert with condition

Time:07-03

I work in python 3. I calculate the average and I would like to use an assert instruction.

moyenne = somme/nombre_notes   if somme==50 and nombre_notes==4 :   assert moyenne==12.5 ,"Erreur de calcul" 

This solution is operational but how write my assert in 1 line and begin by assert ....? Thank

CodePudding user response:

You can build the conditional checks into the assertion like this:

somme=50
nombre_notes=4
moyenne = somme/nombre_notes
assert somme == 50 and nombre_notes == 4 and moyenne == 12.5, "Erreur de calcul"

CodePudding user response:

Finally I m a solution : do a unit test assert division(50,4)==12.5, "erreur de calcul"

  • Related