<commit_before>---
layout: lab
num: project1
ready: true
desc: "Doing Mathematical Calculations & String Manipulations with Python"
assigned: 2017-04-27 12:30:00.00-7
due: 2017-05-12 23:59:59.00-7
---
<div markdown="1">

<h1>CS 8, Spring 2016: Programming Project 1</h1>
<h2>Due: Friday, 5/12 11:59pm</h2>

<strong>Before you begin:</strong>
Read all of Miller/Ranum chapters 1, 2 and 3 and obtain copies of these 7 files:
<ol>
<li>    sphere.py</li>
<li>    screensize.py</li>
<li>    fibonacci.py</li>
<li>    findWord.py</li>
<li>    decode.py</li>
<li>    message.txt</li>
<li>    theRaven.txt</li>
</ol>
	
The files are found at <code>[http://cs.ucsb.edu/~zmatni/cs8s17/projects/proj1](http://cs.ucsb.edu/~zmatni/cs8s17/projects/proj1/)</code>, and save them in whatever folder you choose to work on this project (presumably <code>~/cs8/proj1/</code>).
  
Edit the comments at the beginnings of these files to include your name (and the name of your partner, 
if you are working with another student) and the date each program is written. 
This is IMPORTANT, and it applies to all future programs too!

<hr>
<!-- PART 1-->
<h2>sphere.py</h2>
(20 points: some calculations) Add the following four functions to sphere.py (three of them are taken from Exercises 2.1, 2.2 and 2.3 on page 81 of the text, and the other is a natural addition):

<ol type="a">
<code>circumference(r)</code> - to return the circumference of a circle with radius<code>r</code>. [<code>2&pi;r</code>]
<code>area(r)</code> - to return the area of a circle with radius <code>r</code>. [<code>&pi;r<sup>2</sup></code>]
<code>surface(r)</code> - to return the surface area of a sphere with radius
<code>r</code>. [<code>4&pi;r<sup>2</sup></code>]
<code>volume(r)</code> - to return the volume of a sphere with radius
<code>r</code>. [<code>4&pi;r<sup>3</sup>/3</code>]
</ol>

Notes:
<ol>
The function headers must <em>exactly match</em> the ones above, or the testing code will not work.
Use <code>math.pi</code> (after importing the math module) for the value of &pi; in all of these calculations.
We suggest you test them one at a time in the Python shell. When they are all done, you can run the module. Here are two sample runs to which you can compare your results:
</ol>

<pre>
-bash-4.2$ <b>python3 sphere.py</b> <commit_msg>Update proj1.md<commit_after>---
layout: lab
num: project1
ready: true
desc: "Doing Mathematical Calculations & String Manipulations with Python"
assigned: 2017-04-27 12:30:00.00-7
due: 2017-05-12 23:59:59.00-7
---
<div markdown="1">

<h1>CS 8, Spring 2016: Programming Project 1</h1>
<h2>Due: Friday, 5/12 11:59pm</h2>

<strong>Before you begin:</strong>
Read all of Miller/Ranum chapters 1, 2 and 3 and obtain copies of these 7 files:
<ol>
<li>    sphere.py</li>
<li>    screensize.py</li>
<li>    fibonacci.py</li>
<li>    findWord.py</li>
<li>    decode.py</li>
<li>    message.txt</li>
<li>    theRaven.txt</li>
</ol>
	
The files are found at <code><a href="http://cs.ucsb.edu/~zmatni/cs8s17/projects/proj1">http://cs.ucsb.edu/~zmatni/cs8s17/projects/proj1/</a></code>, and save them in whatever folder you choose to work on this project (presumably <code>~/cs8/proj1/</code>).
  
Edit the comments at the beginnings of these files to include your name (and the name of your partner, 
if you are working with another student) and the date each program is written. 
This is IMPORTANT, and it applies to all future programs too!

<hr>
<!-- PART 1-->
<h2>sphere.py</h2>
(20 points: some calculations) Add the following four functions to sphere.py (three of them are taken from Exercises 2.1, 2.2 and 2.3 on page 81 of the text, and the other is a natural addition):

<ol type="a">
<code>circumference(r)</code> - to return the circumference of a circle with radius<code>r</code>. [<code>2&pi;r</code>]
<code>area(r)</code> - to return the area of a circle with radius <code>r</code>. [<code>&pi;r<sup>2</sup></code>]
<code>surface(r)</code> - to return the surface area of a sphere with radius
<code>r</code>. [<code>4&pi;r<sup>2</sup></code>]
<code>volume(r)</code> - to return the volume of a sphere with radius
<code>r</code>. [<code>4&pi;r<sup>3</sup>/3</code>]
</ol>

Notes:
<ol>
The function headers must <em>exactly match</em> the ones above, or the testing code will not work.
Use <code>math.pi</code> (after importing the math module) for the value of &pi; in all of these calculations.
We suggest you test them one at a time in the Python shell. When they are all done, you can run the module. Here are two sample runs to which you can compare your results:
</ol>

<pre>
-bash-4.2$ <b>python3 sphere.py</b> 
{'fraction_non_alphanumeric': 0.1476756756756757, 'fraction_numerical': 0.039135135135135134, 'mean_word_length': 4.157190635451505, 'pattern_counts': {'":': 0, '<': 149, '<?xml version=': 0, '>': 149, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3043094', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1593, 'n_words': 600}