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 = io.StringIO(zenPython)
zenlines = fp.readlines()
zenlines = [ line.strip() for line in zenlines ]
#Add implementation here to set and match patterns
if re.search("-" 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):
self.fahrenheit = fahrenheit
t1=Temperature(32)
t1.celsius=0
---------------------------------------------
class Employee:
def __init__(self, fahrenheit, emp_name):
self.celsius = fahrenheit
def getCelsius(self):
return self.__celsius
def setCelsius(self, value):
self.__celsius = value
celsius = property(getCelsius, setCelsius)
t1=Temperature(32)
print(t1.fahrenheit,t1.celsius)
t1.celsius=95
print(t1.fahrenheit,t1.celsius)
-----------------------------------------------
class Circle:
no_of_circles = 0
def __init__(self,radius):
self.radius = radius
Circle.no_of_circles+=1
def area(self):
return (3.14)*(self.radius**2)
-----------------------------------------------
#Add Circle class implementation here
class Circle:
no_of_circles = 0
def __init__(self,radius):
self.radius = radius
Circle.no_of_circles+=1
def area(self):
return (3.14)*(self.radius**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 self.getPi()*(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:
fp.write(str(input_text))
fp.close()
-------------------------------------------------
# Define 'writeTo' function below, such that
# it writes input_text string to filename.
def writeTo(filename, input_text):
with open(filename, 'w') as fp:
fp.write(str(input_text))
fp.close()
# Define the function 'archive' below, such that
# it archives 'filename' into the 'zipfile'
def archive(zfile, filename):
with zipfile.ZipFile('myarchive.zip', 'w', zipfile.ZIP_DEFLATED) as myarchive:
myarchive.write(filename)
--------------------------------------------------
# Complete the function below.
def run_process(cmd_args):
with subprocess.Popen(cmd_args, stdout=subprocess.PIPE) as p:
r = p.communicate()[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 = fp.write(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 = fp.write(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, gzip.open(zfile, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
---------------------------------------------------
# Complete the function below.
def run_process(cmd_args):
with subprocess.Popen(cmd_args, stdout=subprocess.PIPE) 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
equation1.send(x)
equation2.send(x)
def main(x):
n = numberParser()
n.send(x)
------------------------------------------------------------------
# Complete the function below.
def subst(pattern, replace_str, string):
#susbstitute pattern and return it
new_address=[i.replace("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'''