您好,欢迎访问一九零五行业门户网

搞笑的程序猿:看看你是哪种Python程序员

不久前,在互联网上出现了一篇有趣的文章,讲的是对于同一个问题,不同层次的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 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)) + '\n') //一般人压根看不懂。
专家级程序员
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('\n') 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)) //面向对象,但就此题来说,又长又臭。
其它类似信息

推荐信息