不久前,在互联网上出现了一篇有趣的文章,讲的是对于同一个问题,不同层次的程序员编出的Phthon代码显示出了不同的风格,代码都很简单,有趣。这篇文章的原始出处在这里,我把它整理了一下,并修改了几处错误。

1、编程新手

def factorial(x):

if x == 0:

return 1

else:

return x * factorial(x - 1)

print factorial(6)

2、一年编程经验(学Pascal的)

def factorial(x):

result = 1

i = 2

while i <= x:

result = result * i

i = i + 1

return result

print factorial(6)

3、一年编程经验(学C的)

def fact(x): #{

result = i = 1;

while (i <= x): #{

result *= i;

i += 1;

#}

return result;

#}

print(fact(6))

4、一年编程经验(读过 SICP)

@tailcall

def fact(x, acc=1):

if (x > 1): return (fact((x - 1), (acc * x)))

else: return acc

print(fact(6))

5、一年编程经验(Python)

def Factorial(x):

res = 1

for i in xrange(2, x + 1):

res *= i

return res

print Factorial(6)

6、懒惰的Python程序员

def fact(x):

return x > 1 and x * fact(x - 1) or 1

print fact(6)

7、更懒的Python程序员

f = lambda x: x and x * f(x - 1) or 1

print f(6)

8、Python 专家

fact = lambda x: reduce(int.__mul__, xrange(2, x + 1), 1)

print fact(6)

9、Python 黑客

import sys

@tailcall

def fact(x, acc=1):

if x: return fact(x.__sub__(1), acc.__mul__(x))

return acc

sys.stdout.write(str(fact(6)) + ' ')

10、专家级程序员

from c_math import fact

print fact(6)

11、大英帝国程序员

from c_maths import fact

print fact(6)

12、Web 设计人员

NULL = None

def CalculateAndPrintFactorialEx(dwNumber,

hOutputDevice,

lpLparam,

lpWparam,

lpsscSecurity,

*dwReserved):

if lpsscSecurity != NULL:

return NULL #Not implemented

dwResult = dwCounter = 1

while dwCounter <= dwNumber:

dwResult *= dwCounter

dwCounter += 1

hOutputDevice.write(str(dwResult))

hOutputDevice.write(' ')

return 1

import sys

CalculateAndPrintFactorialEx(6, sys.stdout, NULL, NULL, NULL,

NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)

13、企业级程序员

def new(cls, *args, **kwargs):

return cls(*args, **kwargs)

class Number(object):

pass

class IntegralNumber(int, Number):

def toInt(self):

return new (int, self)

class InternalBase(object):

def __init__(self, base):

self.base = base.toInt()

def getBase(self):

return new (IntegralNumber, self.base)

class MathematicsSystem(object):

def __init__(self, ibase):

Abstract

@classmethod

def getInstance(cls, ibase):

try:

cls.__instance

except AttributeError:

cls.__instance = new (cls, ibase)

return cls.__instance

class StandardMathematicsSystem(MathematicsSystem):

def __init__(self, ibase):

if ibase.getBase() != new (IntegralNumber, 2):

raise NotImplementedError

self.base = ibase.getBase()

def calculateFactorial(self, target):

result = new (IntegralNumber, 1)

i = new (IntegralNumber, 2)

while i <= target:

result = result * i

i = i + new (IntegralNumber, 1)

return result

print StandardMathematicsSystem.getInstance(new (InternalBase,

new (IntegralNumber, 2))).calculateFactorial(new (IntegralNumber, 6))

python搞笑代码-【转】 Python 程序员的进化--搞笑版相关推荐

  1. python表白代码如何运行-程序员如何实现表白代码

    程序员实现表白代码的方法:首先打开代码编辑器:然后输入告白代码[while (life < end) {love++;},var you = function from_future_impor ...

  2. python在哪里写代码比较适合-程序员面试被要求手写代码,你与顶级程序员的差别在哪?...

    原标题:程序员面试被要求手写代码,你与顶级程序员的差别在哪? 前言: Python现在非常火,语法简单而且功能强大,很多同学都想学Python! 所以小的给各位看官们准备了收藏已久的视频教程分享给大家 ...

  3. python自学行吗-上万程序员总结:自学Python,掌握到什么程度就可以找工作了?...

    原标题:上万程序员总结:自学Python,掌握到什么程度就可以找工作了? 前言: Python现在非常火,语法简单而且功能强大,很多同学都想学Python! 在这里把最好的分享给大家!希望能带给大伙儿 ...

  4. Python开发指南[1]之程序员计时小时钟(附源码)

    Python开发指南[1]之程序员计时小时钟 程序之美 前言 主体 运行效果 核心代码 逻辑分析 结束语 程序之美 前言 Python作为一门编程语言,这门语言的魅力和影响力已经远超C#.C++等编程 ...

  5. 猿来小课Python视频老师简述让程序员崩溃的瞬间

    作为一个资深的程序猿,我日常的任务就是和代码无数次交锋,在公司敲代码时不知道你们有没有遇到过让你崩溃的瞬间呢?本篇文章猿来小课Python视频老师就收集整理了一些让程序员崩溃的瞬间,让我们下面一起来对 ...

  6. Python 编程无师自通:专业程序员的养成

    Python 编程无师自通:专业程序员的养成 扫码 · 试读 在学习中拉开技术差距

  7. python和java段子_python程序员幽默段子_谁说码农不懂幽默?只有程序员才看得懂的段子...

    程序员干的工作很枯燥,他们需要段子来消遣,其实他们也很幽默,很风趣的.程序员作为高智商.高收入.高压力群体,经常会有各种自嘲,而且还天生携带段子手基因.不信看看下面这些段子,一般人哪能懂!谁说程序员无 ...

  8. Sublime Text 2 - 性感无比的代码编辑器!程序员必备神器!跨平台支持Win/Mac/Linux,支持32与64位,支持各种流行编程语言的语法高亮、代码补全等...

    Sublime Text 2 - 性感无比的代码编辑器!程序员必备神器!跨平台支持Win/Mac/Linux,支持32与64位,支持各种流行编程语言的语法高亮.代码补全等-- 语法高亮.代码提示补全. ...

  9. [译] 冲冠一怒为代码:论程序员与负能量

    原文地址:Rage Against the Codebase: Programmers and Negativity 原文作者:Way Spurr-Chen 译文出自:掘金翻译计划 本文永久链接:gi ...

最新文章

  1. PHP中的SESSION
  2. 插件化知识储备-Binder和AIDL原理
  3. SSH-KeyGen 的用法 【转载】
  4. mysql中事件失效如何解决
  5. c语言infile和outfile用法,C语言文件读写基本操作DEMO
  6. Java学习的快速入门:10行代码学JQuery
  7. Codeforces 746 G. New Roads
  8. c标签判断true false jsp_北京尚学堂卓越班252天[第042天]——Jsp
  9. stdafx.h预编译头
  10. 给ABBYY添加图像的方法
  11. bootstrap的ajax提交
  12. 非常强大的射击动作游戏源码完整版
  13. SQL 分页查询 返回总条数
  14. 笔记31 笨办法学python练习39可爱的词典
  15. 8 款浏览器兼容性测试工具介绍,需要的赶紧收藏吧!
  16. 【实践】基于CentOS7部署Ceph集群(版本10.2.2)
  17. GDUT2016年ACM新生杯初赛题解
  18. 发国际快递美国专线需要注意什么事项
  19. 手搭深度推荐模型(四) NFM
  20. 一个Android开发者开博一周年的成长日记——送给不知如何下手的【初级开发者】和【在校生】

热门文章

  1. hibernate映射(单向双向的一对多、多对一以及一对一、多对一(转)
  2. poj 2777Count Color
  3. 计算机网络——互动百科
  4. 登录之验证码相关实现
  5. 架设httpd服务器
  6. asp.net select Case条件语句的使用方法
  7. 24个很酷的 CSS3 文本效果示例及教程
  8. 调整viewState的位置
  9. asp.net + winform + log4net 使用示例|using log4net with asp.net/winform
  10. python用什么软件编程1001python用什么软件编程-怎样才能写出 Pythonic 的代码 #P1001#...