11/1/2011 cs python project prime numbers

Upload: matt-carlberg

Post on 07-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 11/1/2011 CS Python Project Prime Numbers

    1/2

    Introduction to Computer Science SK1U

    Fall 2011Instructor: Matthew Carlberg

    Project #3: Prime Numbers

    Due Date: Monday, November 7 at 11:59PM.

    Program Specification: Write a program that computes and prints to the screen theNthprime number, whereNis chosen by the user.

    You will write your program as a single .py file. You will write it and save it in Idlestext editor. You will also use Idle to test and debug your code.

    Background: Recall that a prime number is a number that can only be divided evenly(with no remainder) by 1 and itself. 2 is the first prime number, 3 is the second, 5 is the

    third, 7 is the fourth, 11 is the fifth, and so on. You should test your code to see if it canproperly calculate the 1000th

    prime number, which is 7919.

    Grading: The project will be graded out of 100 points, and the requirements will be as

    follows:

    1) Program implementation grading (80 points)a. (40 points) Non-working code or code with syntax errors.b. (45 points) The program does not define any methods. It allows the

    user to input a number and displays whether or not the number isprime.

    c.

    (50 points) Same as (b) except the program defines and uses thefollowing method:i. isPrime(), which accepts a number x as input and outputs True

    if x is prime and false if x is not prime.

    d. (60 points) Full, working implementation of the ProgramSpecification, but the program defines and uses either one method or

    no methods at all.

    e. (80 points) Full, working implementation of the ProgramSpecification that includes the following two methods:

    i. calculateNthPrimeNumber(), which accepts a numberNasinput and outputs theNth prime number.

    ii. isPrime(), which accepts a number x as input and outputs Trueif x is prime and false if x is not prime.

    Each minor bug in the program will lead to a 5 point deduction.

    2) Commenting (20 points)

  • 8/3/2019 11/1/2011 CS Python Project Prime Numbers

    2/2

    a. Header Comments (10 points): A series of comments at the start ofyour Python file, specifying the author, date, and brief description ofthe entire program.

    b. Inline Comments (10 points): Extensive comments that help explainwhat individual lines or blocks of code do. Write your comments

    with the goal of helping a peer understand your code

    Hints:

    First, ask the user, What prime number do you want me to calculate? Store thenumber in a variableN.

    The method calculateNthPrimeNumber() should acceptNas a parameter. Itshould return (i.e. output) theNth prime number. The code itself will iterates

    through every integer greater than 1 in a while loop, until it has found the Nthprime number.

    The method isPrime() should accept x as a parameter. It should return (i.e.output) True if x is prime and False if x is not prime. The code itself will iteratethrough every number greater than 1 but less than x to identify if any numbersother than 1 and x divide it evenly. Remember that the expression a%b returns

    the remainder after dividing the integer a by the integer b.

    Use print statements liberally in both of these methods to help you debug yourcode. For example, print out information every time you have found a primenumber. Comment these debugging print statements out before you submit the

    code.

    Bonus: The program, as described here, performs too many calculations that are notnecessary for finding theNth prime number. If you can find ways for the computer to

    perform fewer computations than those that are described in this document, it will countas bonus. Create a file called PrimeNumberBonus.txt (which you will also upload toDropbox) to document in what ways you reduced the number of computations. Each

    significant computational savings that you implement will be +5 points.

    Turning in: The project will be submitted as a single file via Dropbox. In your shared

    folder (LastName SK1U?), upload a python file called PrimeNumber.py. If you

    implement the bonus, submit a file called PrimeNumbersBonus.txt.