我有一個課程要做。我需要通過所有需要的6個測試。我已經通過了5次,但有一個關於Python中的類的問題。類錯誤 - 無類型和詮釋 - Python
def doomsday(y):
"""
>>> doomsday(2012)
3
>>> doomsday(1899)
2
>>> doomsday(1923)
3
>>> doomsday(10000)
-1
>>> doomsday(1756)
-1
>>> type(doomsday(2010))
<class 'int'>
"""
try:
y
except ValueError:
return
if y in range (1800, 1899+1):
x = 5
w = y%100
a = w//12
b = w%12
c = b//4
d = (a + b + c)%7
t = x + d
if t>6:
t = t - 7
print (t)
else:
print (t)
elif y in range (1900, 1999+1):
x = 3
w = y%100
a = w//12
b = w%12
c = b//4
d = (a + b + c)%7
t = x + d
if t>6:
t = t - 7
print (t)
else:
print (t)
elif y in range (2000, 2099+1):
x = 2
w = y%100
a = w//12
b = w%12
c = b//4
d = (a + b + c)%7
t = x + d
if t>6:
t = t - 7
print (t)
else:
print (t)
elif y in range (2100, 2199+1):
x = 0
w = y%100
a = w//12
b = w%12
c = b//4
d = (a + b + c)%7
t = x + d
if t>6:
t = t - 7
print (t)
else:
print (t)
else:
x = -1
print (x)
我不能通過這個測試:
type(doomsday(2010))
class 'int'
和錯誤是:
Failed example:
type(doomsday(2010))
Expected:
class 'int'
Got:
0
class 'NoneType'
你的函數不返回任何東西,所以用的'返回值的隱含回報沒有'會發生。如果你想讓你的函數返回一個整數,你需要明確地做。 –
'print'不是'return' –