def test_countdown(self):
from_3 = '3\n2\n1\nBlastoff!'
self.assertEqual(countdown(3), from_3)
from_0 = 'Blastoff!'
self.assertEqual(countdown(0), from_0)
#THIS IS THE TEST
def countdown(n):
while n>0:
print(n)
n=n-1
print("Blastoff!")
#This is my code for the function
它不是通過測試,因爲它是走出來的「無」>倒計時後端(3)而不是「3 \ N2 \ N1 \ nBlastoff!」倒計時功能測試蟒蛇工作
你似乎有混淆返回值和從打印輸出。打印將值打印到標準輸出。這與函數的返回值完全不同。您需要實際返回某些內容才能使用assertEqual。 – Lalaland