码迷,mamicode.com
首页 > 其他好文 > 详细

两种方式实现求n的阶乘

时间:2018-09-25 23:00:05      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:result   pre   循环   return   for   code   test   n的阶乘   turn   

# 通过递归实现求n的阶乘 def my_test(n): if n is 0: return 1 else: return n*my_test(n-1) print(my_test(5)) >> 120 # 通过普通循环实现求n的阶乘 def my_test2(n): result = n for i in range(1,n): result *= i return result print(my_test2(5)) >> 120

两种方式实现求n的阶乘

标签:result   pre   循环   return   for   code   test   n的阶乘   turn   

原文地址:http://blog.51cto.com/10412806/2285586

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!