MC1-Homework-1
Contents
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
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 "Bessell Correction."
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.
Template
Here's a template for what your code should look like:
# 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 your functions 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.
Udacity login instructions
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: GT-Udacity Login
Here's a helpful video. Once you're in, visit the above link again, or navigate to the course from My Courses.
Note: DO NOT log in using your personal Udacity account, in case you have one.
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:
- Any libraries not listed in the "allowed" section above.
- Any code you did not write yourself.