Python求階乘
阿新 • • 發佈:2021-02-17
技術標籤:python
Python求階乘
# coding:utf-8
# 使用遞迴求階乘
print('Recursive factorial !')
enterNumber = int(input('Please enter a number:\n'))
# 求階乘的方法
def recursiveMethod(number):
'''
This method is used to find the factorial !!!
return:recursiveMethod
'''
if number == 0:
return 0
elif number == 1 :
return 1
else:
return number*recursiveMethod(number-1)
# 呼叫
print('{}的階乘是:{}'.format(enterNumber,recursiveMethod(enterNumber)))