Difference between revisions of "MC1-Homework-1"

From Quantitative Analysis Software Courses
Jump to navigation Jump to search
(Included link to test cases)
 
(19 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
The purpose of this assignment is to get you started programming in Python.  Note that we'll be using Python 2.7 for this course (not Python 3.0).  This assignment is structured like many of the homeworks and projects for this course, namely that you are to create a Python function that solves a specific problem.  We will call your function and verify that it provides the correct answer.
 
The purpose of this assignment is to get you started programming in Python.  Note that we'll be using Python 2.7 for this course (not Python 3.0).  This assignment is structured like many of the homeworks and projects for this course, namely that you are to create a Python function that solves a specific problem.  We will call your function and verify that it provides the correct answer.
  
'''Note''': You will be able to write, test and submit your code for this assignment on Udacity. So you don't need to have Python installed, but you're welcome to work on your computer if you do (we'll provide further instructions on what libraries to install as part of MC2-Homework-2).
+
==Task==
  
==Required, Allowed & Prohibited==
+
You should create and test your code in the virtual machine you've installed separately.
  
Required:
+
Your task for this homework is to write two Python functions: One named <tt>stdev_p()</tt> that computes the population standard deviation of a list of numbers, and another named <tt>stdev_s()</tt> that computes the sample standard deviation. We will use the definitions of population and sample standard deviation provided at wikipedia [[https://en.wikipedia.org/wiki/Standard_deviation here]]. Specifically the sample stdev should use the "Bessel Correction."
* Your project must be coded in Python 2.7.x.
 
* Your code must run on one of the university-provided computers (e.g. buffet02.cc.gatech.edu), or on one of the provided virtual images.
 
* Your code must run in less than 5 seconds on one of the university-provided computers.
 
  
Allowed:
+
Note that only the functions stdev_s() and stdev_p() will be tested. The main part of the code will not be called or tested. The main code is only there to help you test your code.
* You can develop your code on your personal machine, but it must also run successfully on one of the university provided machines or virtual images.
 
* Your code may use standard Python libraries.
 
* You may use the NumPy, SciPy and Pandas libraries.
 
* Small sections of code (up to 5 lines) that you collected from other students or the internet.
 
* Code provided by the instructor, or allowed by the instructor to be shared.
 
  
Prohibited:
+
==You have to write it yourself!==
* Any libraries not listed in the "allowed" section above.
 
* Any code you did not write yourself (except for the 5 line rule in the "allowed" section).
 
* Any Classes other than Random that create their own instance variables for later use (e.g., learners like kdtree).
 
  
==Task==
+
We want you to implement the functions described above using basic Python functions and control flow comments (e.g., while, for, etc.).  You are not allowed to import any libraries besides the standard math library.
 
 
Your task for this homework is to write a Python function named <tt>nth_prime(N)</tt> that computes and returns the Nth prime number. A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itselfIf we were to call your function in a Python interpreter, we'd expect output like this:
 
  
<PRE>
+
==Template==
>>> nth_prime(1)
 
2
 
>>> nth_prime(5)
 
11
 
</PRE>
 
 
 
==Suggestions==
 
  
 
Here's a template for what your code should look like:
 
Here's a template for what your code should look like:
  
 
<PRE>
 
<PRE>
def nth_prime(N):
+
import math as m
    # TODO: Write code here that computes the Nth prime
+
 
     result = N * 2 # e.g. this code finds the Nth even number
+
# calculate the population standard deviation
 +
def stdev_p(data):
 +
     result = 2.0 # your code goes here
 
     return result
 
     return result
</PRE>
 
  
If you are developing locally, you will need to save your code in a Python file, say <TT>primer.py</TT>.  If you additionally add the following lines to your code, you can run the code as a program and test it to see that it finds the correct answer:
+
# calculate the sample standard deviation
 
+
def stdev_s(data):
<PRE>
+
     result = 1.9 # your code goes here
def test_run():
+
    return result
     print nth_prime(5)
 
  
 
if __name__ == "__main__":
 
if __name__ == "__main__":
     test_run()
+
     test = [2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0]
 +
    print "the population stdev is", stdev_p(test)
 +
    print "the sample stdev is", stdev_s(test)
 
</PRE>
 
</PRE>
  
You can run your program using the command: <tt>python primer.py</tt>
+
Cut and paste this template into a local file <TT>stdev_code.py</TT>.  Note that the main part of the code tests the two functions.  Note also that your main code <b>will not be tested</b> by the auto grading code.  Only the specific functions we describe will be called and tested.
 +
 
 +
You can run your program using the command: <tt>python stdev_code.py</tt>
  
 
==Resources and ideas==
 
==Resources and ideas==
Line 65: Line 49:
 
==What to turn in==
 
==What to turn in==
  
Test and submit your code via the Udacity platform. Continue here: [https://www.udacity.com/course/viewer#!/c-ud501/l-4180469313/m-4236488542 MC1-Homework-1 - Instructions]
+
* Submit your code as a single file <tt>stdev_code.py</tt> via t-square.  It is essential that you use that name exactly.
 +
* Do not submit other files.
 +
* Do not submit zip files.
 +
* Make sure your code file is named correctly.
 +
* Under no circumstance should you submit a word document.
 +
 
 +
==Rubric==
 +
 
 +
* 4 test cases: We will test your code against 4 cases (25% per case).  Each case will be deemed "correct" if:
 +
** 12.5%: stdev_p = reference answer within 10%
 +
** 12.5%: stdev_s = reference answer within 10%
  
==Udacity login instructions==
+
==Test cases==
  
If you are a GT OMSCS or on-campus student taking this course for credit, you must log in to Udacity using your Georgia Tech account:
+
Here are the test cases used while grading. These are updated each semester and released after grading.
[https://login.gatech.edu/cas/login?service=http%3A%2F%2Fweb.iam.gatech.edu%2Fudacity-login%2F GT-Udacity Login]
+
* [[MC1-Homework-1-Test-Cases-spr2016]]
  
Here's a [https://www.youtube.com/watch?v=pyqirZW_sT8 helpful video]. Once you're in, visit the above link again, or navigate to the course from '''My Courses'''.
+
==Required, Allowed & Prohibited==
  
'''Note''': DO NOT log in using your personal Udacity account, in case you have one.
+
Required:
 +
* Your project must be coded in Python 2.7.x.
 +
* Your code must run successfully on one of the university-provided computers (e.g. buffet02.cc.gatech.edu), or on the provided virtual image.
 +
* Your code must solve a 1000 element list in less than 1 second on one of the university-provided computers.
 +
 
 +
Allowed:
 +
* You can develop your code on your personal machine, but it must also run successfully on one of the university provided machines or virtual images.
 +
* Your code may import the Python math library.
 +
 
 +
Prohibited:
 +
* Print statements in your function definitions.  No need to print anything.
 +
* Any libraries not listed in the "allowed" section above.
 +
* Any code you did not write yourself.

Latest revision as of 15:49, 26 January 2016

Overview

The purpose of this assignment is to get you started programming in Python. Note that we'll be using Python 2.7 for this course (not Python 3.0). This assignment is structured like many of the homeworks and projects for this course, namely that you are to create a Python function that solves a specific problem. We will call your function and verify that it provides the correct answer.

Task

You should create and test your code in the virtual machine you've installed separately.

Your task for this homework is to write two Python functions: One named stdev_p() that computes the population standard deviation of a list of numbers, and another named stdev_s() that computes the sample standard deviation. We will use the definitions of population and sample standard deviation provided at wikipedia [here]. Specifically the sample stdev should use the "Bessel Correction."

Note that only the functions stdev_s() and stdev_p() will be tested. The main part of the code will not be called or tested. The main code is only there to help you test your code.

You have to write it yourself!

We want you to implement the functions described above using basic Python functions and control flow comments (e.g., while, for, etc.). You are not allowed to import any libraries besides the standard math library.

Template

Here's a template for what your code should look like:

import math as m

# calculate the population standard deviation
def stdev_p(data):
    result = 2.0 # your code goes here
    return result

# calculate the sample standard deviation
def stdev_s(data):
    result = 1.9 # your code goes here
    return result

if __name__ == "__main__":
    test = [2.0, 4.0, 4.0, 4.0, 5.0, 5.0, 7.0, 9.0]
    print "the population stdev is", stdev_p(test)
    print "the sample stdev is", stdev_s(test)

Cut and paste this template into a local file stdev_code.py. Note that the main part of the code tests the two functions. Note also that your main code will not be tested by the auto grading code. Only the specific functions we describe will be called and tested.

You can run your program using the command: python stdev_code.py

Resources and ideas

What to turn in

  • Submit your code as a single file stdev_code.py via t-square. It is essential that you use that name exactly.
  • Do not submit other files.
  • Do not submit zip files.
  • Make sure your code file is named correctly.
  • Under no circumstance should you submit a word document.

Rubric

  • 4 test cases: We will test your code against 4 cases (25% per case). Each case will be deemed "correct" if:
    • 12.5%: stdev_p = reference answer within 10%
    • 12.5%: stdev_s = reference answer within 10%

Test cases

Here are the test cases used while grading. These are updated each semester and released after grading.

Required, Allowed & Prohibited

Required:

  • Your project must be coded in Python 2.7.x.
  • Your code must run successfully on one of the university-provided computers (e.g. buffet02.cc.gatech.edu), or on the provided virtual image.
  • Your code must solve a 1000 element list in less than 1 second on one of the university-provided computers.

Allowed:

  • You can develop your code on your personal machine, but it must also run successfully on one of the university provided machines or virtual images.
  • Your code may import the Python math library.

Prohibited:

  • Print statements in your function definitions. No need to print anything.
  • Any libraries not listed in the "allowed" section above.
  • Any code you did not write yourself.