A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6. Write program that prompts the user to enter a number then displays a message indicating whether the number is prime. The program must contain the following functions (named as defined below). Each function must perform the task outlined next to it main() – controls program. Displays if the number is prime. Produces a special message if the user entered a 1 for user input. get_intro() – Displays an introduction to the program. determine_prime() - Uses modulus to determine if a number is prime. Returns a Boolean value. validate_input() – validates that user input is a positive whole number. Entering in a string or float must not break the program. Use try\except. Returns int do_again() – asks the user if they want to restart the program. Program must not break but start or exit cleanly. main() get_intro() determine_prime() validate_input) do_again()
Looking for help with determine_prime() and do_again()
What I have so far;
def get_intro():
print( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print("In Math, prime numbers are whole numbers greater than 1, that have only two factors the number 1 and the number itself. This
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
def validate_input():
while True:
try:
newNum = int(input("Enter a postive whole number to check if it is prime: "))
if newNum <= 0:
print("Value must be a whole number greater than 0!")
continue
except ValueError:
print("Value must be a whole number!")
continue
else:
return newNum
def determine_prime(isWhole):
while isWhole <= 1:
print("The definition of a prime number is a positive interger that has exactly two positive divisors.")
print("The number 1 only has one positive divisor, so the number 1 is not prime.")
validateInput()
else:
prime = True
for i in range(2, isWhole):
if isWhole%i == 0:
print("This number", isWhole,"is not prime")
prime = False
if prime:
print("This number", isWhole,"is prime")
# Main
get_intro()
isWhole = validate_input()
determine_prime(isWhole)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images