In [58]:
"Adapted from John DeNero's CS61A Introductory Python Demo"
denero_url = "https://youtu.be/2SopsFYlGr4?list=PL6BsET-8jgYUD6BYw7Dp7EXteeDxcTaaT"

#Just setting everything up for the demo
from operator import add
from IPython.display import Image
from IPython.display import YouTubeVideo
youTube_url = "M1wMfOwlAZ8?t=4s" 
In [42]:
#We can use our computer to do easy math! 

2+2
Out[42]:
4
In [43]:
#We can use our computer to do hard math! 

7*7*7 + 7*7*7 + 11*11*11
Out[43]:
2017
In [44]:
#What else can a computer do?

print("Hello, World!")
Hello, World!
In [45]:
#Shakespeare Demo

Image(url= "https://www.biography.com/.image/c_fill,cs_srgb,dpr_1.0,g_face,h_300,q_80,w_300/MTE1ODA0OTcxNzgzMzkwNzMz/william-shakespeare-194895-1-402.jpg")
Out[45]:
In [46]:
shakes = open("shakespeare.txt")
In [47]:
text = shakes.read().split()
In [48]:
text[:25]
Out[48]:
['A',
 "MIDSUMMER-NIGHT'S",
 'DREAM',
 'Now',
 ',',
 'fair',
 'Hippolyta',
 ',',
 'our',
 'nuptial',
 'hour',
 'Draws',
 'on',
 'apace',
 ':',
 'four',
 'happy',
 'days',
 'bring',
 'in',
 'Another',
 'moon',
 ';',
 'but',
 'O']
In [49]:
len(text)
Out[49]:
980637
In [50]:
text.count('the')
Out[50]:
23272
In [51]:
text.count("thou")
Out[51]:
4501
In [52]:
text.count("you")
Out[52]:
12361
In [53]:
text.count("forsooth")
Out[53]:
40
In [54]:
text[:25]
Out[54]:
['A',
 "MIDSUMMER-NIGHT'S",
 'DREAM',
 'Now',
 ',',
 'fair',
 'Hippolyta',
 ',',
 'our',
 'nuptial',
 'hour',
 'Draws',
 'on',
 'apace',
 ':',
 'four',
 'happy',
 'days',
 'bring',
 'in',
 'Another',
 'moon',
 ';',
 'but',
 'O']
In [55]:
text.count(',')
Out[55]:
81827
In [56]:
text.count(',')/len(text) * 100
Out[56]:
8.34427010198473
In [59]:
YouTubeVideo( youTube_url )
Out[59]:
In [ ]: