Discuss / Python / 作业

作业

Topic source

阿萌QVQ

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

def fact(n): ''' Calculate 12...*n

>>> fact(1)
1
>>> fact(10)
3628800
>>> fact(-1)
Traceback (most recent call last):
    ...
ValueError
'''
if n < 1:
    raise ValueError()
if n == 1:
    return 1
return n * fact(n - 1)

  • 1

Reply