Chapter 14 Exercise 1 : Python tutorial 173

preview_player
Показать описание
Guys please help this channel to reach 20,000 subscribers. I'll keep uploading quality content for you.

Python is easy programming language to learn and anyone can learn it, and these tutorials are 100% free in hindi.

You can share this playlist with your brother, sisters and friends. This will surely add some values to their life.

If you follow this complete playlist of python tutorial surely you will learn everything about python programming language.

This is exercise for decorators.

Рекомендации по теме
Комментарии
Автор

import time
def time_calculator(func):
def wrappers(*args, **kwargs):

''' this function calculate time '''
t1 = time.time()

func(*args, **kwargs)

t2 = time.time()

print(f'time taken to execute = {t2 - t1}')


return wrappers

@time_calculator
def p(l):
for i in range(1, l):
print(i)

print(p(100))

RahulChauhan-diiy
Автор

#Decorator Function
import time
def func(fun):
def inner_func( ):
print(f"this functione took {t3} to run")
fun( )
return inner_func


#General add function
@func
def add():
print('this is add function')


#Time Execution_Calculation
t1 = time.time() # Start time
print("This place has been made for testing of time purpose")
t2=time.time() # End time
t3=t2-t1 #difference of both : time taken to run only print line

add()

manishramesh
Автор

from time import time
def time_calculator(fun):
def wrap(*args):
start = time()
print(fun(*args))
end = time()
print(f"your code takes {end-start} sec")
return wrap
@time_calculator
def table(n):
for i in range(1, 11):
print(f"{n} x {i} = {n*i}")
table(2)

mohanbarman
Автор

from time import time
def time_calculator(func):
def wrapper(*args, **kwargs):
'''This function can calculate time.'''
t1 = time()
func()
t2 = time()
print(f'\nTime taken: {t2 - t1:.2f}sec')
return wrapper


@time_calculator


def printer():
return [(i**2)*i//i for i in
printer()

MRGolum
Автор

import time
def func(fun):
def war(*args, **kwargs):
print(f"this functione took {t3} to run")
return fun(*args, **kwargs)
return war
t1 = time.time()
@func
def add():
print('this is function')
t2=time.time()
t3=t2-t1
add()

mukeshdaryani
Автор

import time
from functools import wraps
def time_calculate(func):
@wraps(func)
def wrapper(*args, **kwargs):
'''this is wrapper function...'''
print(f"executing.... {func.__name__}")
print(f"{func.__doc__}")
time1=time.time()
returned_func=func(*args, **kwargs)
time2=time.time()
total= time2-time1
print(f"this function took {total}sec to run")
return returned_func
return wrapper

@time_calculate
def my_map(func, l):
'''this function provide loop for every item in l...'''
return [func(i) for i in l]

l=[1, 2, 3, 4]
print(my_map(lambda a:a**2, l))

masterdon
Автор

Bhai python 3.7 latest hai use install kr skte h kya?

abhaykumar
welcome to shbcf.ru