我有一个课程要做。我需要通过所有需要的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' –