Skip to content

Commit a0bdd2f

Browse files
author
Carolyn.Evans
committed
Conflicts: .gitignore
2 parents 10da281 + f6786ff commit a0bdd2f

File tree

281 files changed

+189028
-1689
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

281 files changed

+189028
-1689
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
slides_sources/build
22
.idea
33
.DS_Store
4+
#ignore compiled files, sublime workspace and project files
45
*.pyc
6+
*.sublime*

Examples/Session03/test_script.py

100755100644
File mode changed.

Examples/Session04/junk2.txt

Whitespace-only changes.

Examples/Session05/codingbat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
# Python > Warmup-1 > sleep_in
1010

11+
1112
def sleep_in(weekday, vacation):
1213
return not (weekday == True and vacation == False)
1314

Examples/Session06/cigar_party.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
When squirrels get together for a party, they like to have cigars.
5+
A squirrel party is successful when the number of cigars is between
6+
40 and 60, inclusive. Unless it is the weekend, in which case there
7+
is no upper bound on the number of cigars.
8+
9+
Return True if the party with the given values is successful,
10+
or False otherwise.
11+
"""
12+
13+
14+
def cigar_party(cigars, is_weekend):
15+
"""
16+
basic solution
17+
"""
18+
if ( 40 <= cigars <= 60 ) or ( cigars >= 40 and is_weekend):
19+
return True
20+
else:
21+
return False
22+
23+
24+
def cigar_party3(cigars, is_weekend):
25+
"""
26+
conditional expression
27+
"""
28+
return (cigars >= 40) if is_weekend else (cigars >= 40 and cigars <= 60)

Examples/Session06/html_render/html_render.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,16 @@
22

33
"""
44
Python class example.
5-
65
"""
76

87

98
# The start of it all:
109
# Fill it all in here.
1110
class Element(object):
12-
tag = 'html'
13-
indent = ' '
1411

1512
def __init__(self, content=None):
16-
if content is not None:
17-
self.content = [str(content)]
18-
else:
19-
self.content = []
20-
13+
pass
2114
def append(self, new_content):
22-
""" add some new content to the element"""
23-
self.content.append(new_content)
24-
15+
pass
2516
def render(self, file_out, ind=""):
26-
"""render the content to the given file like object"""
27-
28-
file_out.write( ind+"<"+self.tag+">\n"+ind+self.indent )
29-
file_out.write( ("\n"+ind+self.indent).join(self.content) )
30-
file_out.write( "\n"+ind+"</"+self.tag+">" )
31-
32-
17+
file_out.write("just something as a place holder...")
-1.58 KB
Binary file not shown.

Examples/Session06/html_render/run_html_render.py

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66
Uncomment the steps as you add to your rendering.
77
88
"""
9-
from io import open, StringIO
9+
10+
from cStringIO import StringIO
1011

1112

1213
# importing the html_rendering code with a short name for easy typing.
1314
import html_render as hr
14-
reload(hr)
15+
reload(hr) # reloading in case you are running this in iPython
16+
# -- we want to make sure the latest version is used
1517

1618

1719
## writing the file out:
18-
def render(page, filename):
20+
def render_page(page, filename):
1921
"""
2022
render the tree of elements
2123
@@ -24,26 +26,26 @@ def render(page, filename):
2426
"""
2527

2628
f = StringIO()
27-
page.render(f, u" ")
29+
page.render(f, " ")
2830

29-
f.seek(0)
31+
f.reset()
3032

3133
print f.read()
3234

33-
f.seek(0)
34-
open(filename, 'w', encoding="utf-8").write( f.read() )
35+
f.reset()
36+
open(filename, 'w').write( f.read() )
3537

3638

3739
## Step 1
3840
##########
3941

4042
page = hr.Element()
4143

42-
page.append(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text")
44+
page.append("Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text")
4345

44-
page.append(u"And here is another piece of text -- you should be able to add any number")
46+
page.append("And here is another piece of text -- you should be able to add any number")
4547

46-
render(page, u"test_html_output1.html")
48+
render_page(page, "test_html_output1.html")
4749

4850
# ## Step 2
4951
# ##########
@@ -52,134 +54,134 @@ def render(page, filename):
5254

5355
# body = hr.Body()
5456

55-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text"))
57+
# 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"))
5658

57-
# body.append(hr.P(u"And here is another piece of text -- you should be able to add any number"))
59+
# body.append(hr.P("And here is another piece of text -- you should be able to add any number"))
5860

5961
# page.append(body)
6062

61-
# render(page, u"test_html_output2.html")
63+
# render_page(page, "test_html_output2.html")
6264

6365
# # Step 3
6466
# ##########
6567

6668
# page = hr.Html()
6769

6870
# head = hr.Head()
69-
# head.append(hr.Title(u"PythonClass = Revision 1087:"))
71+
# head.append(hr.Title("PythonClass = Revision 1087:"))
7072

7173
# page.append(head)
7274

7375
# body = hr.Body()
7476

75-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text"))
76-
# body.append(hr.P(u"And here is another piece of text -- you should be able to add any number"))
77+
# 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"))
78+
# body.append(hr.P("And here is another piece of text -- you should be able to add any number"))
7779

7880
# page.append(body)
7981

80-
# render(page, u"test_html_output3.html")
82+
# render_page(page, "test_html_output3.html")
8183

8284
# # Step 4
8385
# ##########
8486

8587
# page = hr.Html()
8688

8789
# head = hr.Head()
88-
# head.append(hr.Title(u"PythonClass = Revision 1087:"))
90+
# head.append(hr.Title("PythonClass = Revision 1087:"))
8991

9092
# page.append(head)
9193

9294
# body = hr.Body()
9395

94-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
95-
# style=u"text-align: center; font-style: oblique;"))
96+
# 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",
97+
# style="text-align: center; font-style: oblique;"))
9698

9799
# page.append(body)
98100

99-
# render(page, u"test_html_output4.html")
101+
# render_page(page, "test_html_output4.html")
100102

101103
# # Step 5
102104
# #########
103105

104106
# page = hr.Html()
105107

106108
# head = hr.Head()
107-
# head.append(hr.Title(u"PythonClass = Revision 1087:"))
109+
# head.append(hr.Title("PythonClass = Revision 1087:"))
108110

109111
# page.append(head)
110112

111113
# body = hr.Body()
112114

113-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
114-
# style=u"text-align: center; font-style: oblique;"))
115+
# 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",
116+
# style="text-align: center; font-style: oblique;"))
115117

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

118120
# page.append(body)
119121

120-
# render(page, u"test_html_output5.html")
122+
# render_page(page, "test_html_output5.html")
121123

122124
# # Step 6
123125
# #########
124126

125127
# page = hr.Html()
126128

127129
# head = hr.Head()
128-
# head.append(hr.Title(u"PythonClass = Revision 1087:"))
130+
# head.append(hr.Title("PythonClass = Revision 1087:"))
129131

130132
# page.append(head)
131133

132134
# body = hr.Body()
133135

134-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
135-
# style=u"text-align: center; font-style: oblique;"))
136+
# 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",
137+
# style="text-align: center; font-style: oblique;"))
136138

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

139-
# body.append(u"And this is a ")
140-
# body.append( hr.A(u"http://google.com/", "link") )
141-
# body.append(u"to google")
141+
# body.append("And this is a ")
142+
# body.append( hr.A("http://google.com/", "link") )
143+
# body.append("to google")
142144

143145
# page.append(body)
144146

145-
# render(page, u"test_html_output6.html")
147+
# render_page(page, "test_html_output6.html")
146148

147149
# # Step 7
148150
# #########
149151

150152
# page = hr.Html()
151153

152154
# head = hr.Head()
153-
# head.append(hr.Title(u"PythonClass = Revision 1087:"))
155+
# head.append(hr.Title("PythonClass = Revision 1087:"))
154156

155157
# page.append(head)
156158

157159
# body = hr.Body()
158160

159-
# body.append( hr.H(2, u"PythonClass - Class 6 example") )
161+
# body.append( hr.H(2, "PythonClass - Class 6 example") )
160162

161-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
162-
# style=u"text-align: center; font-style: oblique;"))
163+
# 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",
164+
# style="text-align: center; font-style: oblique;"))
163165

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

166-
# list = hr.Ul(id=u"TheList", style=u"line-height:200%")
168+
# list = hr.Ul(id="TheList", style="line-height:200%")
167169

168-
# list.append( hr.Li(u"The first item in a list") )
169-
# list.append( hr.Li(u"This is the second item", style="color: red") )
170+
# list.append( hr.Li("The first item in a list") )
171+
# list.append( hr.Li("This is the second item", style="color: red") )
170172

171173
# item = hr.Li()
172-
# item.append(u"And this is a ")
173-
# item.append( hr.A(u"http://google.com/", u"link") )
174-
# item.append(u"to google")
174+
# item.append("And this is a ")
175+
# item.append( hr.A("http://google.com/", "link") )
176+
# item.append("to google")
175177

176178
# list.append(item)
177179

178180
# body.append(list)
179181

180182
# page.append(body)
181183

182-
# render(page, u"test_html_output7.html")
184+
# render_page(page, "test_html_output7.html")
183185

184186
# # Step 8
185187
# ########
@@ -188,37 +190,37 @@ def render(page, filename):
188190

189191

190192
# head = hr.Head()
191-
# head.append( hr.Meta(charset=u"UTF-8") )
192-
# head.append(hr.Title(u"PythonClass = Revision 1087:"))
193+
# head.append( hr.Meta(charset="UTF-8") )
194+
# head.append(hr.Title("PythonClass = Revision 1087:"))
193195

194196
# page.append(head)
195197

196198
# body = hr.Body()
197199

198-
# body.append( hr.H(2, u"PythonClass - Class 6 example") )
200+
# body.append( hr.H(2, "PythonClass - Class 6 example") )
199201

200-
# body.append(hr.P(u"Here is a paragraph of text -- there could be more of them, but this is enough to show that we can do some text",
201-
# style=u"text-align: center; font-style: oblique;"))
202+
# 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",
203+
# style="text-align: center; font-style: oblique;"))
202204

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

205-
# list = hr.Ul(id=u"TheList", style=u"line-height:200%")
207+
# list = hr.Ul(id="TheList", style="line-height:200%")
206208

207-
# list.append( hr.Li(u"The first item in a list") )
208-
# list.append( hr.Li(u"This is the second item", style="color: red") )
209+
# list.append( hr.Li("The first item in a list") )
210+
# list.append( hr.Li("This is the second item", style="color: red") )
209211

210212
# item = hr.Li()
211-
# item.append(u"And this is a ")
212-
# item.append( hr.A(u"http://google.com/", "link") )
213-
# item.append(u"to google")
213+
# item.append("And this is a ")
214+
# item.append( hr.A("http://google.com/", "link") )
215+
# item.append("to google")
214216

215217
# list.append(item)
216218

217219
# body.append(list)
218220

219221
# page.append(body)
220222

221-
# render(page, u"test_html_output8.html")
223+
# render_page(page, "test_html_output8.html")
222224

223225

224226

0 commit comments

Comments
 (0)