szymcio10

my_range_time

Mar 27th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import time
  2.  
  3. def dec(func):
  4.     def warp(*args):
  5.         a = time.clock()
  6.         func(*args)
  7.         b = time.clock()
  8.         print "czas: ",b-a
  9.         return func(*args)
  10.     return warp
  11.  
  12. @dec
  13. def my_range(*args):
  14.     li = []
  15.     if len(args)>3 or len(args)<1:
  16.         raise ValueError
  17.     if len(args)==1:
  18.         k=1.0
  19.         a=0.0
  20.         while a<=args[0]:
  21.             li.append(a)
  22.             a+=k
  23.     elif len(args)==2:
  24.         k=1.0
  25.         a=args[0]
  26.         while a<=args[1]:
  27.             li.append(a)
  28.             a+=k
  29.     elif len(args)==3:
  30.         a = args[0]
  31.         k = args[2]
  32.         if args[2]==0.0: raise ValueError
  33.         elif args[2]>0:
  34.             while a <= args[1]:
  35.                 li.append(a)
  36.                 a += k
  37.         else:
  38.             while a >= args[1]:
  39.                 li.append(a)
  40.                 a += k
  41.     return li
  42.  
  43.  
  44.  
  45. print my_range(3)
Advertisement
Add Comment
Please, Sign In to add comment