def outer(func):
def inner():
print("Accessing :",
func.__name__)
return func()
return inner
def greet():
return 'Hello!'
wish = outer(greet)
wish()
def outer(func):
def inner():
print("Accessing :",
func.__name__)
return func()
return inner
def greet():
return 'Hello!'
greet = outer(greet) # decorating 'greet'
greet() # calling new 'greet'
def outer(func):
def inner():
print("Accessing :",
func.__name__)
return func()
return inner
@outer
def greet():
return 'Hello!'
greet()
------------------------------
fp = [Link](zenPython)
zenlines = [Link]()
zenlines = [ [Link]() for line in zenlines ]
#Add implementation here to set and match patterns
if [Link]("-" or "*", zenlines)== True
print('Yes')
#Add portions implementation here
return portions
---------------------------
# Define the abstract class 'Animal' below
# with abstract method 'say'
class Animal(ABC):
def __init__(self):
super().__init__()
@abstractmethod
def say(self):
return "I speak Cooooo"
# Define class Dog derived from Animal
# Also define 'say' method inside 'Dog' class
class Dog(Animal):
def say(self):
super().say()
return "I speak Booooo"
------------------------
# Add Celsius class implementation below.
class Celsius:
def __get__(self, obj, owner):
return self.__celsius
def __set__(self, obj, value):
self.__celsius = value
class Temperature:
celsius = Celsius()
def __init__(self, fahrenheit):
[Link] = fahrenheit
t1=Temperature(32)
[Link]=0
---------------------------------------------
class Employee:
def __init__(self, fahrenheit, emp_name):
[Link] = fahrenheit
def getCelsius(self):
return self.__celsius
def setCelsius(self, value):
self.__celsius = value
celsius = property(getCelsius, setCelsius)
t1=Temperature(32)
print([Link],[Link])
[Link]=95
print([Link],[Link])
-----------------------------------------------
class Circle:
no_of_circles = 0
def __init__(self,radius):
[Link] = radius
Circle.no_of_circles+=1
def area(self):
return (3.14)*([Link]**2)
-----------------------------------------------
#Add Circle class implementation here
class Circle:
no_of_circles = 0
def __init__(self,radius):
[Link] = radius
Circle.no_of_circles+=1
def area(self):
return (3.14)*([Link]**2)
@classmethod
def getCircleCount(self):
return Circle.no_of_circles
-------------------------------------------
#Add circle class implementation here
class Circle(object):
no_of_circles=0
def __init__(self, radius):
self.__radius = radius
Circle.no_of_circles+=1
@staticmethod
def getPi():
return 3.14
def area(self):
return [Link]()*(self.__radius**2)
@classmethod
def getCircleCount(self):
return Circle.no_of_circles
--------------------------------------------------
# Complete the function below.
def writeTo(filename, input_text):
with open(filename, 'w') as fp:
[Link](str(input_text))
[Link]()
-------------------------------------------------
# Define 'writeTo' function below, such that
# it writes input_text string to filename.
def writeTo(filename, input_text):
with open(filename, 'w') as fp:
[Link](str(input_text))
[Link]()
# Define the function 'archive' below, such that
# it archives 'filename' into the 'zipfile'
def archive(zfile, filename):
with [Link]('[Link]', 'w', zipfile.ZIP_DEFLATED) as myarchive:
[Link](filename)
--------------------------------------------------
# Complete the function below.
def run_process(cmd_args):
with [Link](cmd_args, stdout=[Link]) as p:
r = [Link]()[0]
return (r)
------------------------------------------
def detecter(element):
def isIn(sequence):
#return(type(element),type(sequence))
if str(element) in str(sequence):
return(True)
else:
return(False)
return isIn
detect30 = detecter(30) # 'c1' is a closure
detect45 = detecter(45) # 'c2' is a closure
print(detect30 (30))
print(detect45(45))
---------------------------------------------
----------------------------------------------
def factory(n):
#n=0
#n=int(input())
def current():
return str(n)
def counter():
return str(n+1)
return current,counter
f_current,f_counter=factory(int(input()))
-------------------------------------------
# Complete the function below.
def writeTo(filename, input_text):
with open(filename, 'w') as fp:
content = [Link](input_text)
-------------------------------------------
import gzip
import shutil
# Define 'writeTo' function below, such that
# it writes input_text string to filename.
def writeTo(filename, input_text):
with open(filename, 'w') as fp:
content = [Link](input_text)
# Define the function 'archive' below, such that
# it archives 'filename' into the 'zipfile'
def archive(zfile, filename):
with open(filename, 'rb') as f_in, [Link](zfile, 'wb') as f_out:
[Link](f_in, f_out)
---------------------------------------------------
# Complete the function below.
def run_process(cmd_args):
with [Link](cmd_args, stdout=[Link]) as p:
return (b'Hello')
------------------------------------------------------
# Define the coroutine function 'linear_equation' below.
def linear_equation(a, b):
while True:
x=yield
t=eval('a*(x**2)+b')
print('Expression, '+str(a)+'*x^2 + '+str(b)+', with x being '+str(x)+'
equals '+str(t))
-----------------------------------------------------------
# Define 'coroutine_decorator' below
def coroutine_decorator(coroutine_func):
def wrapper(*args, **kwdargs):
c = coroutine_func(*args, **kwdargs)
next(c)
return c
return wrapper
# Define coroutine 'linear_equation' as specified in previous exercise
@coroutine_decorator
def linear_equation(a, b):
while True:
x=yield
t=eval('a*(x**2)+b')
print('Expression, '+str(a)+'*x^2 + '+str(b)+', with x being '+str(x)+'
equals '+str(t))
----------------------------------------------------------------
# Define 'coroutine_decorator' below
def coroutine_decorator(coroutine_func):
def wrapper(*args, **kwdargs):
c = coroutine_func(*args, **kwdargs)
next(c)
return c
return wrapper
# Define coroutine 'linear_equation' as specified in previous exercise
@coroutine_decorator
def linear_equation(a, b):
while True:
x=yield
t=eval('a*(x**2)+b')
print('Expression, '+str(a)+'*x^2 + '+str(b)+', with x being '+str(x)+'
equals '+str(t))
# Define the coroutine function 'numberParser' below
@coroutine_decorator
def numberParser():
equation1 = linear_equation(3, 4)
equation2 = linear_equation(2, -1)
# code to send the input number to both the linear equations
[Link](x)
[Link](x)
def main(x):
n = numberParser()
[Link](x)
------------------------------------------------------------------
# Complete the function below.
def subst(pattern, replace_str, string):
#susbstitute pattern and return it
new_address=[[Link]("ROAD","RD.").replace("BRD.","BROAD") for i in pattern]
return new_address
def main():
addr = ['100 NORTH MAIN ROAD',
'100 BROAD ROAD APT.',
'SAROJINI DEVI ROAD',
'BROAD AVENUE ROAD']
#Create pattern Implementation here
new_address=subst(addr,"a","b")
#Use subst function to replace 'ROAD' to 'RD.',Store as new_address
return new_address
'''For testing the code, no input is required'''