Funny programmer: Look at what type of Python programmer you are, python programmer

Source: Internet
Author: User
Tags getbase ibase mul

Funny programmer: Look at what type of Python programmer you are, python programmer

Not long ago, there was an interesting article on the Internet about the Python Code Compiled by Python programmers of different levels on the same issue, the code is simple and interesting. Let's take a look at the entire process of advanced Python program. (Sneer)

Novice Programming

Def factorial (x): if x = 0: return 1 else: return x * factorial (x-1) // It's not easy, iterative, novice. Print factorial (6)

One year of programming experience (learning Pascal's)

def factorial(x):    result = 1    i = 2    while i <= x:      resultresult = result * i      ii = i + 1    return result  print factorial(6)  

One year of programming experience (C)

def fact(x): #{    result = i = 1;    while (i <= x): #{      result *= i;      i += 1;    #}    return result;  #}  print(fact(6)) 

One year of programming experience (I have read the tool)

@tailcall  def fact(x, acc=1):    if (x > 1):      return (fact((x - 1), (acc * x)))    else:         return acc  print(fact(6))  

One year programming experience (Python)

def Factorial(x):    res = 1    for i in xrange(2, x + 1):      res *= i      return res   print Factorial(6) 

Lazy Python programmers

def fact(x):    return x > 1 and x * fact(x - 1) or 1  print fact(6)  

More lazy Python programmers

F = lambda x: x and x * f (x-1) or 1 // anonymous function, amazing. Programmers are really lazy! Print f (6)

Python expert

Fact = lambda x: reduce (int. _ mul __, xrange (2, x + 1), 1) print fact (6) // experts are amazing.

 Python hacker

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') // generally cannot understand.

Expert programmers

from c_math import fact  print fact(6)  

British Empire programmer

From c_maths import fact print fact (6) Web designer 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 programmers

import os  def fact(x):    os.system('factorial ' + str(x))  fact(6)  

Windows programmers

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 + = 1 hOutputDevice. write (str (dwResult) hOutputDevice. write ('\ n') return 1 import sys CalculateAndPrintFactorialEx (6, sys. stdout, NULL, NULL) // you may be confused...

Enterprise programmers

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 failed t 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 + new (IntegralNumber, 1) return result print StandardMathematicsSystem. getInstance (new (InternalBase, new (IntegralNumber, 2 ))). calculateFactorial (new (IntegralNumber, 6) // plane To the object, but for this question, it is long and smelly.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.