187k views
4 votes
Create a program that checks whether a number is a prime number and displays the total number of factors if it is not a prime number.

Prime Number Checker
Please enter an integer between 2 and 5000: 1
Invalid integer. Please try again.
Please enter an integer between 2 and 5000: 2
2 is a prime number.
Try again? (y/n): y
Please enter an integer between 2 and 5000: 3
3 is a prime number.
Try again? (y/n): y
Please enter an integer between 2 and 5000: 4
4 is NOT a prime number. It has 3 factors.
Try again? (y/n): y
Please enter an integer between 2 and 5000: 6
6 is NOT a prime number. It has 4 factors.
Try again? (y/n): n
Bye!
A prime number is only divisible by two factors (1 and itself). For example, 7 is a prime number because it is only divisible by 1 and 7.
If the number is not a prime number, the program should display its number of factors. For example, 6 has four factors (1, 2, 3, and 6).
Store the code that gets a valid integer for this program in its own function.
Store the code that calculates the number of factors for a number in its own function.
Store the rest of the code that gets input and displays output in the main() function. Divide this code into functions whenever you think it would make that code easier to read and maintain.
Allow the user to repeat this process as many times as they like

1 Answer

4 votes

Final answer:

The programming task involves creating a prime number checker that also informs users of the total number of factors for non-prime numbers. It requires structuring the code into functions and includes a repeat option.

Step-by-step explanation:

The question asks for a program to check whether a number is a prime number and to display the total number of factors if it is not. The program should prompt the user to enter an integer between 2 and 5000 and then assess whether the integer is a prime number. If the number is not a prime number, the program should inform the user and display the total count of its factors. This program is to be structured by organizing functionality into separate functions; one for getting a valid integer, another for calculating the number of factors, and the main function that handles user input and output. The ability for the user to repeat the process should also be included.

User JerryCauser
by
7.7k points