[英]Python3 instruction assert with condition
我在 python 3 中工作。我計算平均值,我想使用斷言指令。
moyenne = somme/nombre_notes if somme==50 and nombre_notes==4 : assert moyenne==12.5 ,"Erreur de calcul"
該解決方案是可操作的,但是如何在 1 行中編寫我的斷言並以斷言開頭......? 感謝
您可以像這樣將條件檢查構建到斷言中:
somme=50
nombre_notes=4
moyenne = somme/nombre_notes
assert somme == 50 and nombre_notes == 4 and moyenne == 12.5, "Erreur de calcul"
最后,我找到了一個解決方案:進行單元測試,如下所示:
assert division(50, 4) == 12.5, "erreur de calcul"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.