- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
不久前,在互联网上出现了一篇有趣的文章,讲的是对于同一个问题,不同层次 的Python程序员编出的Python代码显示出了不同的风格,代码都很简单,有趣。 下而让我们一起来看看一个Python程序员是进阶的全过程。
AD:
不久前,在互联网上出现了一篇有趣的文章,讲的是对于同一个问题,不同 层次的Python程序员编出的Python代码显示出了不同的风格,代码都很简单, 有趣。
编程新手
丄? def factorial(x):
. if x == 0:
? return 1
else:
return x * factorial(x 一 1)
print factorial(6)
一年编程经验(学Pascal的)
1. def factorial(x):
? result = 1
. i = 2
? while i = x:
5. resultresult = result * i
6 . ii = i + 1
return result
print factorial(6)
一年编程经验(学c的)
1. def
fact(x): #{
2 .
result = i = 1;
3 .
while (i = x): #{
4 .
result *= i;
5 .
i += 1;
6 .
#}
7 .
return result;
8. #}
9 ? print(fact(6))
一年编程经验(读过SICP)
1 ?
? def fact(x,
. if (x :
,acc=l):
1): return (fact((x 一 1), (acc * x)))
4 . else:
return acc
5 ? print(fact (6))
一年编程经验(Python)
1. def Factorial(x):
? res = 1
for i in xrange(2, x + 1):
? res *= i
? return res
. print Factorial(6)
懒惰的Python程序员
? def fact(x):
. return x 1 and x * fact(x - 1) or 1
? print fact (6)
更懒的Python程序员
1. f = lambda x: x and x * f (x - 1) or 1
2 ? print f(6)
Python专家
丄.fact = lambda x: reduce (int. mul_, xrange (2 z x + 1) z 1)
2 ? print fact(6)
Python黑客
? import sys
. ?tailcall
. def fact(xz acc=l):
if x: return fact(x. sub (1), acc. mul (x))
? return acc
. sys-stdout.write(str(fact(6)) + \n1)
专家级程序员
1. from c_math import fact
2 ? print fact (6)
大英帝国程序员
1. from c_maths import fact
2 ? print fact (6)
Web设计人员
1 ? def
factorial(x):
2 .
# ——
3 .
# Code snippet from The Math Vault
4 .
# Calculate factorial (C) Arthur Smith 1999
5 .
#
6 .
result = str (1)
7 .
i = 1 #Thanks Adam
8 .
while i = x:
9 .
#result = result * i #Its faster to use *=
10 .
#result = str(result * result + i)
11.
#result = int(result *= i) #??????
12 .
result = str(int(result) * i)
13 .
#result = int(str(result) * i)
14?
i = i + 1
15.
return result
16.
print factorial(6)
Unix程序员
? import os
? def fact(x):
3? os?system(,factorial 1 + str(x))
. fact (6)
Windows程序员
1. NULL = None
. def CalculateAndPrintFactorialEx(dwNumber,
? hOutputDevice,
lpLparam,
lpWparam, Ip
文档评论(0)