Está en la página 1de 2

Introduction to Computer Science SK1U Fall 2011 Instructor: 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 the Nth prime number, where N is chosen by the user. You will write your program as a single .py file. You will write it and save it in Idles text 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 can properly 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 is prime. c. (50 points) Same as (b) except the program defines and uses the following 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 Program Specification, but the program defines and uses either one method or no methods at all. e. (80 points) Full, working implementation of the Program Specification that includes the following two methods: i. calculateNthPrimeNumber(), which accepts a number N as input and outputs the Nth prime number. ii. isPrime(), which accepts a number x as input and outputs True if 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)

a. Header Comments (10 points): A series of comments at the start of your Python file, specifying the author, date, and brief description of the entire program. b. Inline Comments (10 points): Extensive comments that help explain what 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 the number in a variable N. The method calculateNthPrimeNumber() should accept N as a parameter. It should return (i.e. output) the Nth prime number. The code itself will iterates through every integer greater than 1 in a while loop, until it has found the Nth prime 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 iterate through every number greater than 1 but less than x to identify if any numbers other 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 your code. For example, print out information every time you have found a prime number. Comment these debugging print statements out before you submit the code. Bonus: The program, as described here, performs too many calculations that are not necessary for finding the Nth prime number. If you can find ways for the computer to perform fewer computations than those that are described in this document, it will count as bonus. Create a file called PrimeNumberBonus.txt (which you will also upload to Dropbox) 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.

También podría gustarte