Как стать автором
Обновить

Эволюция Python-программиста

Время на прочтение3 мин
Количество просмотров2.8K

Начинающий


  1. def factorial(x):
  2.     if x == 0:
  3.         return 1
  4.     else:
  5.         return x * factorial(x - 1)
  6. print factorial(6)


Программирующий уже год (Ранее изучавший Pascal)


  1. def factorial(x):
  2.     result = 1
  3.     i = 2
  4.     while i <= x:
  5.         result = result * i
  6.         i = i + 1
  7.     return result
  8. print factorial(6)



Программирующий уже год (Ранее изучавший C)


  1. def fact(x)#{
  2.     result = i = 1;
  3.     while (<= x)#{
  4.         result *= i;
  5.         i += 1;
  6.     #}
  7.     return result;
  8. #}
  9. print(fact(6))


Программирующий уже год (начитавшийся SICP)


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


Программирующий уже год на Python (ранее изучавший 1С)


  1. def ObrabotkaObchisleniya():
  2.     // 
  3.     return 0
  4.  
  5. def Soobschit(TekstSoobscheniya):
  6.     print TekstSoobscheniya
  7.  
  8. def Faktorial(Znacheniye):
  9.     return Znacheniye*Faktorial(Znacheniye-1)
  10. Soobschit(Faktorial(6))
  11.  
  12. Sutki = 84000


Изучающий Python и иногда Brainfuck


  1. import os
  2. def fact(x):
  3.     file = open("code.b"'w')
  4.     file.write(">++++++++++>>>+>+[>>>+[-[<<<<<[+<<<<<]>>[[-]>[<<+>+>-]<[>+<-]<[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>+<-[>[-]>>>>+>+<<<<<<-[>+<-]]]]]]]]]]]>[<+>-]+>>>>>]<<<<<[<<<<<]>>>>>>>[>>>>>]++[-<<<<<]>>>>>>-]+>>>>>]<[>++<-]<<<<[<[>+<-]<<<<]>>[->[-]++++++[<++++++++>-]>>>>]<<<<<[<[>+>+<<-]>.<<<<<]>.>>>>]")
  5.     file.close()
  6.     # todo: implement x parameter
  7.     os.system('/usr/bin/bf code.b')
  8. fact(6)


Программирующий уже год на Python


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


Ленивый Python'щик


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


Очень ленивый Python'щик


  1. f = lambda x: x and x * f(x - 1) or 1
  2. print f(6)


Python'щик — эксперт


  1. fact = lambda x: reduce(int.__mul__xrange(2, x + 1)1)
  2. print fact(6)


Python'щик — хакер


  1. import sys
  2. @tailcall
  3. def fact(x, acc=1):
  4.     if x: return fact(x.__sub__(1), acc.__mul__(x))
  5.     return acc
  6. sys.stdout.write(str(fact(6)) + '\n'


Программист-эксперт


  1. from c_math import fact
  2. print fact(6)


Английский программист-эксперт


  1. from c_maths import fact
  2. print fact(6)


Веб-программист


  1. def factorial(x):
  2.     #-------------------------------------------------
  3.     #--- Сниппет вычисления факториала          ---
  4.     #--- Использовать на свой страх и риск (с) Василий Пупкин 2010 ---
  5.     #-------------------------------------------------
  6.     result = str(1)
  7.     i = 1 #Благодарность за хак Ивану
  8.     while i <= x:
  9.         #result = result * i  #Наверное лучше использовать *=
  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-программист


  1. import os
  2. def fact(x):
  3.     os.system('factorial ' + str(x))
  4. fact(6)


Windows-программист


  1. NULL = None
  2. def CalculateAndPrintFactorialEx(dwNumber,
  3.                                  hOutputDevice,
  4.                                  lpLparam,
  5.                                  lpWparam,
  6.                                  lpsscSecurity,
  7.                                  *dwReserved):
  8.     if lpsscSecurity != NULL:
  9.         return NULL #Not implemented
  10.     dwResult = dwCounter = 1
  11.     while dwCounter <= dwNumber:
  12.         dwResult *= dwCounter
  13.         dwCounter += 1
  14.     hOutputDevice.write(str(dwResult))
  15.     hOutputDevice.write('\n')
  16.     return 1
  17. import sys
  18. CalculateAndPrintFactorialEx(6sys.stdout, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)


Программист крупной конторы


  1. def new(cls, *args, **kwargs):
  2.     return cls(*args, **kwargs)
  3.  
  4. class Number(object):
  5.     pass
  6.  
  7. class IntegralNumber(int, Number):
  8.     def toInt(self):
  9.         return new (intself)
  10.  
  11. class InternalBase(object):
  12.     def __init__(self, base):
  13.         self.base = base.toInt()
  14.  
  15.     def getBase(self):
  16.         return new (IntegralNumber, self.base)
  17.  
  18. class MathematicsSystem(object):
  19.     def __init__(self, ibase):
  20.         Abstract
  21.  
  22.     @classmethod
  23.     def getInstance(cls, ibase):
  24.         try:
  25.             cls.__instance
  26.         except AttributeError:
  27.             cls.__instance = new (cls, ibase)
  28.         return cls.__instance
  29.  
  30. class StandardMathematicsSystem(MathematicsSystem):
  31.     def __init__(self, ibase):
  32.         if ibase.getBase() !new (IntegralNumber, 2):
  33.             raise NotImplementedError
  34.         self.base = ibase.getBase()
  35.  
  36.     def calculateFactorial(self, target):
  37.         result = new (IntegralNumber, 1)
  38.         i = new (IntegralNumber, 2)
  39.         while i <= target:
  40.             result = result * i
  41.             i = i + new (IntegralNumber, 1)
  42.         return result
  43.  
  44. print StandardMathematicsSystem.getInstance(new (InternalBase, new (IntegralNumber, 2))).calculateFactorial(new (IntegralNumber, 6))


А к какому типу принадлежишь ты, %username%?

upd.: Интересно, кто тихо по-подлому карму сливает? Коль имеешь возражение — имей смелость высказать его в комментах.
Теги:
Хабы:
+119
Комментарии38

Публикации

Изменить настройки темы

Истории

Работа

Python разработчик
132 вакансии
Data Scientist
60 вакансий

Ближайшие события

Weekend Offer в AliExpress
Дата20 – 21 апреля
Время10:00 – 20:00
Место
Онлайн
Конференция «Я.Железо»
Дата18 мая
Время14:00 – 23:59
Место
МоскваОнлайн