Discuss / Python / 那个报错的, 填写对应的报错信息那还是有点懵,我是先随便写一句,后台报完错,复制过来的

那个报错的, 填写对应的报错信息那还是有点懵,我是先随便写一句,后台报完错,复制过来的

Topic source

一雷叔一

#1 Created at ... [Delete] [Delete and Lock User]

def fact(n):

'''
>>> d1 = fact
>>> x = 1
>>> d1(x)
1
>>> y = 4
>>> d1(y)
24
>>> z = 0
>>> d1(z)
Traceback (most recent call last):
    ...
ValueError
>>> a = 'abc'
>>> d1(a)
Traceback (most recent call last):
    ...
TypeError: unorderable types: str() < int()
'''

if n < 1:
    raise ValueError()
if n == 1:
    return 1
return n * fact(n - 1)

if name == 'main': import doctest doctest.testmod()


  • 1

Reply