Download Assignment 14 - Number Analyzer

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Addition wikipedia , lookup

Proofs of Fermat's little theorem wikipedia , lookup

Elementary mathematics wikipedia , lookup

Transcript
Mr. Seok
Intro to Computer Programming
Assignment 14 – Number Analyzer
Name: _________________________________
Directions:
In this assignment, you will be writing two parts. As part of the welcome page, greet the user and ask the
user which program he/she would like to run. Then, after they are done with one program, allow the user
to return to the “main menu” and choose again.
Example Run:
>>
Welcome to the Number Analyzer Code!
You can choose to:
(1) analyze a single integer
(2) examine a range of numbers
(3) exit the program
Which would you like to choose? 2
Okay, great! Let’s take a look at a range of numbers.
(Runs part 2 …)
You can choose to:
(1) analyze a single integer
(2) examine a range of numbers
(3) exit the program
Which would you like to choose? analyze a number
I’m sorry, I didn’t get that. Please try again.
You can choose to:
(1) analyze a single integer
(2) examine a range of numbers
(3) exit the program
Which would you like to choose? 1
Okay, let’s analyze a number.
(Runs part 1 …)
You can choose to:
(1) analyze a single integer
(2) examine a range of numbers
(3) exit the program
Which would you like to choose? 3
Okay, goodbye.
Part 1: Write a program that analyzes a number given by the user.
- You should restrain them to integers between 1 and 100,000, inclusive of bounds. Continually
prompt the user until they input a valid entry.
- Define a function to determine whether the function is even.
- Define a function to determine whether the function is a perfect square.
- Define a function to determine whether the number is prime.
- All three of your functions are limited to returning Boolean values (True or False).
- Then, analyze the number given by the user and print out a summary of the results.
- Continually ask the user if they would like to continue the program by analyzing another number
until they say “no.”
Example Run:
>>
Enter a number (1 - 100,000): 0
Invalid! Try again.
Enter a number (1 - 100,000): 480
480 is an even number.
480 is not a perfect square.
480 is not a prime number.
Would you like to analyze another number? yes
Enter a number (1 - 100,000): 3
3 is an odd number.
3 is not a perfect square.
3 is a prime number.
Would you like to analyze another number? no
Part 2: Extend your number analyzer to determine all the prime numbers between ranges of numbers.
- Copy and paste your prime number function from part 1.
- Ask the user for a range of numbers (restrict the user to numbers 1 – 100,000). Make sure they
give you a valid range. The first number they enter should be lower than the second number,
giving a valid range.
- Then, determine all the numbers in the range which are prime and print them out.
- Continually prompt the user to see if they would like to analyze another range.
Example Run:
>>
Enter the lower number: 0
Invalid! Try again.
Enter the lower number: 2
Enter the higher number: 100000000
Invalid! Try again.
Enter the higher number: 10
3 is a prime number.
5 is a prime number.
7 is a prime number.
Would you like to analyze another range of numbers? yes
Enter the lower number: 5
Enter the higher number: 2000000
Invalid! Try again.
Enter the higher number: 2
This is not a valid range. Try a greater value.
Enter the higher number: 20
5 is a prime number.
7 is a prime number.
11 is a prime number.
13 is a prime number.
17 is a prime number.
19 is a prime number.
Would you like to analyze another number? no
Your program should be named as follows: Pd __ LastName FirstName Assignment 14 and inputted
into my Dropbox. Again, you will not have access to my Dropbox as the computer will make clear to you
but it does not mean your file did not go through.
Note: After some speculation, I will be running tests to check your assignments. However, you will not be able to run
these tests on your own as you did during the classwork assignment. They will only be accessible to me. If your
assignment passes all my tests without any errors, you will receive a perfect score for the assignment. If not, then
you will be graded as prior assignments.