Fresco Code Python Application Programming
Fresco Code Python Application Programming
Fresco Code Python Application Programming
File 2 :
fp = io.StringIO(zenPython)
return fp
File 3 :
fp = io.StringIO(zenPython)
zenlines=fp.readlines()[:5]
return(zenlines)
File 4:
File 5:
==============================================
Handson #2 - Give a Try PDH # 2 -
return finalw
=================================================
Handson #3 - Welcome to Python Database Connectivity
File 1 :
import sqlite3
def main():
conn = sqlite3.connect('SAMPLE.db')
#create connection cursor
cursor = conn.cursor()
#create table ITEMS using the cursor
query = "CREATE TABLE ITEMS(item_id , item_name , item_descr , iption ,
item_category , quantity_in_stock)"
cursor.execute(query)
#commit connection
conn.commit()
#close connection
conn.close()
File 2 :
def main():
conn = sqlite3.connect('SAMPLE.db')
cursor = conn.cursor()
This study source was downloaded by 100000832806195 from CourseHero.com on 01-04-2022 04:10:13 GMT -06:00
https://www.coursehero.com/file/67036952/Fresco-code-Python-Application-programming/
cursor.execute(sql_statement)
try:
cursor.executemany(sql,items)
File 3:
File 4:
File 5:
===========================================
File 1 - Closures
def detecter(element):
def isIn(sequence):
temp = 0
for i in sequence:
if i == element:
temp = temp+1
if temp > 0:
return True
else:
return False
return isIn
This study source was downloaded by 100000832806195 from CourseHero.com on 01-04-2022 04:10:13 GMT -06:00
https://www.coursehero.com/file/67036952/Fresco-code-Python-Application-programming/
detect30 = detecter(30)
detect45 = detecter(45)
File 2 :
def factory(n=0):
def current():
return n
def counter():
nonlocal n
n += 1
return n
f_current,f_counter = factory(int(input()))
===================================================
File 1:
def log(func):
def inner(*args, **kwdargs):
str_template = "Accessed the function -'{}' with arguments {}
".format(func.__name__,args)+"{}"
return str_template
return inner
@log
def greet(msg):
return msg
File 2:
@log
def average(n1,n2,n3):
return (n1+n2+n3)/3
File 3:
def bold_tag(func):
return inner
@bold_tag
def say(msg):
return msg
File 4:
This study source was downloaded by 100000832806195 from CourseHero.com on 01-04-2022 04:10:13 GMT -06:00
https://www.coursehero.com/file/67036952/Fresco-code-Python-Application-programming/
def inner(*args, **kwdargs):
return '<i>'+func(*args, **kwdargs)+'</i>'
return inner
@italic_tag
def say(msg):
return msg
File 5:
@italic_tag
def greet():
msg = 'Hello World! Welcome to Python Programming Language' #input()
return msg
File 6:
@italic_tag
@bold_tag
=======================================================
class Animal(ABC):
@abstractmethod
def say(self):
pass
# 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")
=====================================================
File 1 :
class Circle:
no_of_circles = 0
def __init__(self,radius):
self.radius = radius
Circle.no_of_circles += 1
def area(self):
return round((3.14*self.radius*self.radius),2)
File 2 :
class Circle:
no_of_circles = 0
def __init__(self,radius):
self.radius = radius
Circle.no_of_circles += 1
This study source was downloaded by 100000832806195 from CourseHero.com on 01-04-2022 04:10:13 GMT -06:00
https://www.coursehero.com/file/67036952/Fresco-code-Python-Application-programming/
def area(self):
return round((3.14*self.radius*self.radius),2)
@classmethod
def getCircleCount(self):
return Circle.no_of_circles
File 3:
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 round((self.getPi()*self.radius*self.radius),2)
@classmethod
def getCircleCount(self):
return Circle.no_of_circles
==============================================
File 1 :
File 2 :
File 3 :
=====================================================
File 1 :
while True:
n =yield
t = (a*(n**2))+b
string = "Expression, "+str(a)+"*x^2 + "+str(b)+", with x being "+str(n)
+" equals "+str(t)
print(string)
This study source was downloaded by 100000832806195 from CourseHero.com on 01-04-2022 04:10:13 GMT -06:00
https://www.coursehero.com/file/67036952/Fresco-code-Python-Application-programming/
File 2 :
def coroutine_decorator(coroutine_func):
def wrapper(*args,**kwdargs):
c = coroutine_func(*args,**kwdargs)
next(c)
return c
return wrapper
File 3:
def main(x):
n = numberParser()
#n.send(x)
=========================================================
Handson # 10 Descriptors
class Celsius:
class Temperature:
celsius = Celsius()
This study source was downloaded by 100000832806195 from CourseHero.com on 01-04-2022 04:10:13 GMT -06:00
https://www.coursehero.com/file/67036952/Fresco-code-Python-Application-programming/
def __init__(self, initial_f):
self.fahrenheit = initial_f
This study source was downloaded by 100000832806195 from CourseHero.com on 01-04-2022 04:10:13 GMT -06:00
https://www.coursehero.com/file/67036952/Fresco-code-Python-Application-programming/
Powered by TCPDF (www.tcpdf.org)