CMSC 201

Homework 6 - Due 10/30

This homework must be submitted by 5pm on the due date to get any credit.

In this homework, we'll be working on integrating smaller parts of a program into a larger whole. Please pay attention to the formatting, as we will require your output be in the same format as ours.

You will be writing a program that analyzes numbers for the user. You will print a menu, asking them if they want to find the greatest common divisor of two numbers, whether a number is perfect, the goldbach decomposition of a number, or all the prime factors of a number. The user should also have an option to quit. You are required to have the following functions (but you are welcome to use more):

  1. GCD(num1, num2)--this function should take two integers and return the largest number that evenly divides both integers.
  2. isPerfect(num1)--takes a single integer and returns True is the number is equal to half the sum of all of its positive divisors, and false otherwise.
  3. goldbach(num1)--takes a single, positive even integer greater than 4 and returns two primes, the sum of which is that num1.
  4. primeFactors(num1)--takes a single, positive integer and returns a list of all the prime factors of that integer.
  5. getNumber(message, minimum)--prints message, and then asks the user for a number. If the number is less than min, the function will loop, continuing to ask the user for a number until the user enters a number larger than min. The function then returns that number.

If the user enters a number that is not amoung the menu options, or a number that is not appropriate for a given test, they should be reprompted to enter one until a number in the correct range is entered. Sample output is below:


Please enter a choice:
1. Greatest common divisor
2. Perfect number check
3. Goldbach decomposition
4. Prime Factors
5. Quit
1
Please enter a positive integer:
60
Please enter a positive integer:
40
The greatest common divisor of 60 and 40 is 20

Please enter a choice:
1. Greatest common divisor
2. Perfect number check
3. Goldbach decomposition
4. Prime Factors
5. Quit
2
Please enter a positive integer:
-3
Number not acceptable.
Please enter a positive integer:
10
10 is not a perfect number.

Please enter a choice:
1. Greatest common divisor
2. Perfect number check
3. Goldbach decomposition
4. Prime Factors
5. Quit
2
Please enter a positive integer:
6
6 is a perfect number.

Please enter a choice:
1. Greatest common divisor
2. Perfect number check
3. Goldbach decomposition
4. Prime Factors
5. Quit
8
Number not acceptable

Please enter a choice:
1. Greatest common divisor
2. Perfect number check
3. Goldbach decomposition
4. Prime Factors
5. Quit
3
Please enter a positive even integer greater than 4:
2
Number not acceptable.
Please enter a positive even integer greater than 4:
8
The goldbach decomposition of 8 is 3 and 5.

Please enter a choice:
1. Greatest common divisor
2. Perfect number check
3. Goldbach decomposition
4. Prime Factors
5. Quit
4
Please enter a positive integer:
15
The prime factors of 15 are [1, 3, 5]

Please enter a choice:
1. Greatest common divisor
2. Perfect number check
3. Goldbach decomposition
4. Prime Factors
5. Quit
5
Quitting...

Submitting

When you've finished your homework, use the submit command to submit the file. You must be logged into your account and you must be in the same directory as the file you're trying to submit. At the Linux prompt, type

submit cs201 HW6 hw6.py

After entering the submit command shown above, you should get a confirmation that submit worked correctly:

Submitting hw6.py...OK

If not, check your spelling and that you have included each of the required parts and try again.

You can check your submission by entering:

submitls cs201 HW6

You should see the name of the file that you just submitted, in this case hw6.py