Skip to content

update html and rad and diam of circle #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Compression_Lab_10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

feast = ["lambs", "sloths", "orangutans", "breakfast cereals", "fruit bats"]

compression = [delicacy.capitalize() for delicacy in feast]

print(compression[0])

comp = [delicacy for delicacy in feast if len(delicacy) > 6]

print (comp)

print("length of feast: ", len(feast))
print("length of comp: ", len(comp))


list_of_tuples = [(1, 'lumberjack'), (2, 'inquisition'), (4, 'spam')]

new_comprehension = [ skit * number for number, skit in list_of_tuples ]

print(new_comprehension)

2 changes: 1 addition & 1 deletion notebooks/Session09.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
"version": "3.5.0"
}
},
"nbformat": 4,
Expand Down
79 changes: 71 additions & 8 deletions students/Boundb3/Session07/html_project/html_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class Element(object):
#class attributes
tag = "element tag"
indent = " "
print("hi")
#print("hi from class element")
#content = []


def __init__(self, content=None, **attributes): ###!!!could i have added the link attribute here??

#store content
self.content = []


# add an attributes dictionary
self.attributes = attributes

Expand All @@ -49,7 +49,7 @@ def append(self, new_content):
def render_tag(self, current_ind):
# tag and then content for each class
attrs = "".join([' {} ="{}"'.format(key,val) for key, val in self.attributes.items()])
#print("this is self.attributes from render_tag: ", self.attributes)
print("this is self.attributes from render_tag: ", self.attributes)
#indentation + tag + content
tag_str = "{}<{}{}>".format(current_ind, self.__str__(), attrs)
#print("from render_tag: current_ind is '{}' and tag strg is '{}'".format(current_ind, tag_str))
Expand Down Expand Up @@ -99,6 +99,10 @@ class P (Element):
class Html (Element):
tag = "html"
print("subclass tag = : ",tag)

def render(self, file_out, current_ind= ""):
file_out.write("<!DOCTYPE html>\n")
super().render(file_out,current_ind = current_ind)
pass

class Head (Element):
Expand Down Expand Up @@ -164,15 +168,65 @@ class Br (SelfClosingTag):
tag = "br"
pass

class A (Element):
class A (OneLineTag):
tag = "a"

def __init__(self, link, content=None, **attributes):
#self.attributes = "href="
#contentstr = "href=" + '"'+content+'"> ' + link


Element.__init__(self,content, **attributes) #!!! not quite right - needs the format: <a href="http://google.com"> link </a>
self.attributes["href"] = link #class guided answer - THANK you!!
#print("a's link is:", self.link)
print("a's content **** is:", self.content)
print("a's kwrgs extract of href** is:", self.attributes["href"])



def render(self, file_out, current_ind= " default indent"):
print("entering a's rendering func ")
tag_str = '{}<{}{}"{}"> '.format(current_ind, self.__str__(),"href=", self.attributes.get("href"))
file_out.write(tag_str)


for con in self.content:
try:
#render it
print("\t--> con in A is: " , con)
file_out.write(con) #was: stuff_str.render(file_out)
except TypeError as e:
print("hit a snag: ", e, "con is: ", con)
con.render(file_out, current_ind + self.indent ) # was: .write(str(stuff_str)) ### watch it if it is self.tag

#write out closing tag
#was:
#stop at the closing html tag
#end_tag = "</{}>".format(self.tag)
#add that tag to the end of the file object
#file_out.write(end_tag)
file_out.write(" </{}>\n".format(self.tag))


def __init__(self, content=None, link="link",**attributes):
self.attributes = "href="
contentstr = "href=" + '"'+content+'">' + link
super().__init__(contentstr,**attributes) #!!! not quite right - needs the format: <a href="http://google.com"> link </a>

#to over write the default __str__
def __str__(self):
return self.ToString()

def ToString(self):
return "a "


# def render_tag(self, current_ind):
# # tag and then content for each class
# attrs = "".join([' {} ="{}"'.format(key,val) for key, val in self.attributes.items()])
# #print("this is self.attributes from render_tag: ", self.attributes)
# #indentation + tag + content
# tag_str = "{}<{}{}".format(current_ind, self.__str__(), attrs) #removed the extra ">" from this tag render
# #print("from render_tag: current_ind is '{}' and tag strg is '{}'".format(current_ind, tag_str))
# print("a's tag string is",tag_str," and self.string is:", self.__str__())
# return tag_str


#self.link = link
pass
Expand All @@ -192,3 +246,12 @@ def __init__(self,header,content = None,**attributes):
self.header = switchdict[int(header)]
self.tag = self.header
super().__init__(content,**attributes)

class Meta(SelfClosingTag):
tag = "meta"

def __init__(self,content=None, **attributes):
#dfault for charset
if "charset" not in attributes:
attributes["charset"] = "UTF-8"
SelfClosingTag.__init__(self,content,**attributes)
1 change: 1 addition & 0 deletions students/Boundb3/Session07/html_project/play.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'Brennen'
56 changes: 29 additions & 27 deletions students/Boundb3/Session07/html_project/run_html_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def render_page(page, filename):
'''
# # Step 6
# #########

'''
page = hr.Html()

head = hr.Head()
Expand All @@ -152,7 +152,7 @@ def render_page(page, filename):
page.append(body)

render_page(page, "test_html_output6.html")

'''
# # Step 7
# #########
'''
Expand Down Expand Up @@ -188,43 +188,45 @@ def render_page(page, filename):

page.append(body)

render_page(page, "test_html_output7.html")
'''
render_page(page, "test_html_output7a.html")

# # Step 8
# ########
'''
page = hr.Html()

# page = hr.Html()


# head = hr.Head()
# head.append( hr.Meta(charset="UTF-8") )
# head.append(hr.Title("PythonClass = Revision 1087:"))
#make and build the head
head = hr.Head()
head.append( hr.Meta(charset="UTF-8") )
head.append(hr.Title("PythonClass = Revision 1087:"))

# page.append(head)
#tuck head into the page
page.append(head)

# body = hr.Body()
#create and build the body
body = hr.Body()

# body.append( hr.H(2, "PythonClass - Class 6 example") )
body.append( hr.H(2, "PythonClass - Class 6 example") )

# body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
# style="text-align: center; font-style: oblique;"))
body.append(hr.P("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
style="text-align: center; font-style: oblique;"))

# body.append(hr.Hr())
body.append(hr.Hr())

# list = hr.Ul(id="TheList", style="line-height:200%")
list = hr.Ul(id="TheList", style="line-height:200%")

# list.append( hr.Li("The first item in a list") )
# list.append( hr.Li("This is the second item", style="color: red") )
list.append( hr.Li("The first item in a list") )
list.append( hr.Li("This is the second item", style="color: red") )

# item = hr.Li()
# item.append("And this is a ")
# item.append( hr.A("http://google.com", "link") )
# item.append("to google")
item = hr.Li()
item.append("And this is a ")
item.append( hr.A("http://google.com", "link") )
item.append("to google")

# list.append(item)
list.append(item)

# body.append(list)
body.append(list)

# page.append(body)
page.append(body)

# render_page(page, "test_html_output8.html")
render_page(page, "test_html_output8.html")
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
</p>
<hr /> {}
And this is a
<a>
href="http://google.com">link
</a>
<a href="http://google.com"> link </a>
to google
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<title> PythonClass = Revision 1087: </title>
Expand All @@ -17,9 +18,7 @@ <h2> PythonClass - Class 6 example </h2>
</li>
<li>
And this is a
<a>
href="http://google.com">, link
</a>
<a href="http://google.com"> link </a>
to google
</li>
</ul>
Expand Down
27 changes: 27 additions & 0 deletions students/Boundb3/Session07/html_project/test_html_output8.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<head>
<meta /> {'charset': 'UTF-8'}
<title> PythonClass = Revision 1087: </title>
</head>
<body>
<h2> PythonClass - Class 6 example </h2>
<p style ="text-align: center; font-style: oblique;">
Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text
</p>
<hr /> {}
<ul style ="line-height:200%" id ="TheList">
<li>
The first item in a list
</li>
<li style ="color: red">
This is the second item
</li>
<li>
And this is a
<a href="http://google.com"> link </a>
to google
</li>
</ul>
</body>
</html>
93 changes: 93 additions & 0 deletions students/Boundb3/Session09/Circle _S09.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@


#create a circle

class Circle (object):

def __init__(self,radius,*args,**kwargs):
self.radius = radius
self.diameter = radius * 2
self._area = 3.14 * (radius * radius)

################################ radius
@ property
def radius(self):
return self._radius

@ radius.setter
def radius(self,value):

print("*****im in radius setter \t", end="")

if value < 1: print("that is a very small circle!")
if value > 3: print("that is a good size circle!")
self._radius = value

################################ diameter
@ property
def diameter(self):
return self._radius * 2

@ diameter.setter
def diameter(self,value):
print("*****im in diameter setter")
self._radius = (value / 2)
self._diameter = value

################################ area
@ property
def area(self):
return self._area

@ area.setter
def area(self,value):
print("Don't change the area - change the radius: AttributeError")
# try:
# return self._area
# except Exception as e:
# print(e)
# if e == "AttributeError":
# print(e)
# else:
# print ("some kind of error. Details: ", e)
# print("AGAIN - don't do this: change the area - change the radius: AttributeError")
# return "AttributeError"


def from_diameter(self,diameter_value):
radius = diameter_value /2
radius = self.__init__(radius)









c1 = Circle(2)
print("c1's radius is: {} and diameter is {} ".format(c1.radius, c1.diameter))

c2 = Circle(3)
print("c2's radius is: {} and diameter is {} ".format(c2.radius, c2.diameter))
#print("c2's diameter: " , c2.diameter)
#print("c2's radius: " , c2.radius)

c2.diameter = 7
print("c2's radius is: {} and diameter is {} ".format(c2.radius, c2.diameter))
# print("now c2's diameter: " , c2.diameter)
# print("and c2's radius: " , c2.radius)

c1.radius = 5
print("c1's radius is: {} and diameter is {} ".format(c1.radius, c1.diameter))

print("c1.area is {}".format(c1.area))
c1.area = 14
print("c1.area is {}".format(c1.area))

# c4 = Circle.from_diameter(8)
# print("c4's radius is: {} and diameter is {} ".format(c4.radius, c4.diameter))

cd = Circle.from_diameter(8)
print("cd's radius is: {} and diameter is ".format(cd.radius))
Loading