MC1-Homework-1-2015

From Quantitative Analysis Software Courses
Jump to navigation Jump to search

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.

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

Your task for this homework is to write a Python function named nth_prime(N) 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 itself. If we were to call your function in a Python interpreter, we'd expect output like this:

>>> nth_prime(1)
2
>>> nth_prime(5)
11

Suggestions

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

def nth_prime(N):
    # TODO: Write code here that computes the Nth prime
    result = N * 2 # e.g. this code finds the Nth even number
    return result

If you are developing locally, you will need to save your code in a Python file, say primer.py. 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:

def test_run():
    print nth_prime(5)

if __name__ == "__main__":
    test_run()

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

Resources and ideas

What to turn in

You can compose and test your code via the Udacity platform (continue here: MC1-Homework-1 - Instructions), however you must submit your final code via t-square.

  • Submit your code as nth_prime.py via t-square. It is essential that you use exactly that name.

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 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:

  • 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:

  • 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).