关于作者

Discuss / Python / 交作业

交作业

Topic source

YSK射手

#1 Created at ...

def fact(n): '''

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

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


  • 1

Reply

WARNING: You are using an old browser that does not support HTML5. Please choose a modern browser (Chrome / Microsoft Edge / Firefox / Sarafi) to get a good experience.