不久前,在互联网上出现了一篇有趣的文章,讲的是对于同一个问题,不同层次的Python程序员编出的Python代码,显示出了不同的风格,代码都很简单,有趣。下面让我们一起来看看一个Python程序猿进阶的全过程吧。(偷笑)

编程新手

def factorial(x):

if x == 0:

return 1

else:

return x * factorial(x - 1) //不简单啊,迭代,新手哦。

print factorial(6)

一年编程经验(学Pascal的)

def factorial(x):

result = 1

i = 2

while i <= x:

resultresult = result * i

ii = i + 1

return result

print factorial(6)

一年编程经验(学C的)

def fact(x): #{

result = i = 1;

while (i <= x): #{

result *= i;

i += 1;

#}

return result;

#}

print(fact(6))

一年编程经验(读过SICP)

@tailcall

def fact(x, acc=1):

if (x > 1):

return (fact((x - 1), (acc * x)))

else:

return acc

print(fact(6))

一年编程经验(Python)

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程序员

f = lambda x: x and x * f(x - 1) or 1 //匿名函数,厉害。程序猿真是懒人做的!

print f(6)

Python专家

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

print fact(6) //专家厉害啊。

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)) + ' ') //一般人压根看不懂。

专家级程序员

from c_math import fact

print fact(6)

大英帝国程序员

from c_maths import fact

print fact(6)

Web设计人员

def factorial(x):

#-------------------------------------------------

#--- Code snippet from The Math Vault ---

#--- Calculate factorial (C) Arthur Smith 1999 ---

#-------------------------------------------------

result = str(1)

i = 1 #Thanks Adam

while i <= x:

#result = result * i #It's faster to use *=

#result = str(result * result + i)

#result = int(result *= i) #??????

result = str(int(result) * i)

#result = int(str(result) * i)

i = i + 1

return result

print factorial(6)

Unix 程序员

import os

def fact(x):

os.system('factorial ' + str(x))

fact(6)

Windows 程序员

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) //可能自己都晕菜了...

企业级程序员

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. chatgpt赋能python:Python恶搞代码:娱乐和学习的完美结合

    Python恶搞代码:娱乐和学习的完美结合 Python作为一种简单易学的脚本语言,不仅可以用于实现各种实用程序和工具,还可以用来制作有趣的恶搞代码.恶搞代码可以让用户看到一些意想不到和滑稽的结果,同 ...

  2. Python恶搞代码

    文章目录 前言 Tkinter界面设计 Threading多线程 恶搞代码 尾声 前言 快来领取python无限弹窗恶搞代码吧!每天写一些有趣的小程序,带你成为一个浪漫的程序员! Tkinter界面设 ...

  3. 程序猿推送利器:使用Python+Server酱打造微信通知推送利器

    你是否经历过服务器挂掉却浑然不知的彷徨?你是否感受过服务停止很久后才发现事情的严重的感觉?是的,你急需一款轻量级的推送通知系统! Server酱正是这么一款程序猿的好帮手,她通过提供一个超轻量级的AP ...

  4. python server酱_程序猿推送利器:使用Python+Server酱打造微信通知推送利器

    你是否经历过服务器挂掉却浑然不知的彷徨?你是否感受过服务停止很久后才发现事情的严重的感觉?是的,你急需一款轻量级的推送通知系统! Server酱正是这么一款程序猿的好帮手,她通过提供一个超轻量级的AP ...

  5. python画画代码大全_太赞了,微软正式推出 Python 零基础教程!

    公众号关注 "GitHubDaily"设为 "星标",每天带你逛 GitHub!Python 可以说是当今世界最火的编程语言之一了.数据科学家和人工智能从业者们 ...

  6. python任意代码都可以缩进去_我发现了个 Python 黑魔法,执行任意代码都会自动念上一段 『平安经』...

    最近的"平安经"可谓是引起了不小的风波啊. 作为一个正儿八经的程序员,最害怕的就是自己的代码上线出现各种各样的 BUG. 为此,明哥今天分享一个 Python 的黑魔法,教你如何在 ...

  7. 关于程序猿的经典段子:杀一个程序员不需用枪,改三次需求即可

    1.栈和队列的区别是啥? 吃多了拉就是队列;吃多了吐就是栈 2.世界上最遥远的距离不是生与死,而是你亲手制造的BUG就在你眼前,你却怎么都找不到她. 3.<c++程序设计语言>比<c ...

  8. 以下python注释代码、叙述中不正确的是_关于 Python 语言的注释,以下选项中描述错误的是( )_学小易找答案...

    [多选题]下列各项中,企业应通过"其他货币资金"科目核算的经济业务有( ). [其它][变式训练 3]如图所示,用与地面成30°角的300 N的力向右上方拉小车,画出该力的示意图. ...

  9. 【小程序动画合集】10种小程序动画效果实现方法,文章太长建议收藏!

    前言 一提小程序与动画,首先想到的是什么?嗯,微信小程序独创了一套动画玩法,官方支持3种动画方案,分别是 createAnimation . this.animate 和 CSS3动画 . 1. cr ...

最新文章

  1. Django站点管理、视图和URL(管理界面本地化、创建管理员、注册模型类、发布内容到数据库、定义视图、配置URLconf)
  2. 最新调查:等这一波COBOL程序员退休,很多关键岗位就后继无人了
  3. python构造icmp数据包_如何在python中构造ICMP数据包
  4. android确认密码代码,Android自定义View实现验证码or密码输入框
  5. 2015Cocos游戏开发大赛作品——人鱼塞壬
  6. ihtml2document能不能根据id获取dom_使用DOM进行XML文件的解析
  7. oracle rds 运维服务_从Oracle一条新闻说起,为什么我们需要更好更开放的RDS服务?...
  8. 对抗神经网络对抗攻击_您将如何检测针对神经网络的网络攻击?
  9. 教你轻松创建谷歌账号、谷歌邮箱!
  10. 真无线蓝牙耳机哪个好用?学生党蓝牙耳机性价比排行榜
  11. 侧扫声纳内业处理--基于HYPACK2018
  12. 自建数据集系列:实例分割mask->语义分割mask->扩增mask
  13. 解决更改mysql密码时报错Your password does not satisfy the current policy requirements问题
  14. 自制肥鲨HDO2电源降压延长线,支持3S~6S动力电池
  15. python 排列组合_Python 实现排列组合中 nCr 算法
  16. python实现--月报和年报
  17. ffmpeg获取视频时长和分辨率
  18. 怎样在bios屏蔽集成显卡
  19. 如何解决Intel SCS Can not create AD AMT Object error
  20. 0028. Find the Index of the First Occurrence in a string (leetcode in python day7)

热门文章

  1. InstallShield2013 error 6109
  2. WPF: x名称空间
  3. 后台提示云提醒未激活 点击激活删除方法
  4. 设计模式 学习笔记(1)简单工厂模式、策略模式
  5. luogu P1843 奶牛晒衣服 | 二分法
  6. node+ejs模板引擎的应用
  7. javaScript知识点大全
  8. HDU 4714 Tree2cycle
  9. 016--VS2013 C++ 透明动画
  10. NSArray 过滤