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()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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 program will calculate if a number you enter is prime.")
          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)

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()
Transcribed Image Text: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()
In Math, prime numbers are whole numbers greater than 1, that have only two factors the number 1 and the number itself.
This program will calculate if a number you enter is prime
Enter a positive whole number to check if it is prime: -1
Value must be a whole number greater than e!
Enter a positive whole number to check if it is prime: e
Value must be a whole number greater than 0!
Enter a positive whole number to check if it is prime: three
Value must be a whole number!
Enter a positive whole number to check if it is prime: 7
This number 7 is prime
Do you want to run the program again? ('Y' for yes, anything else to quit)
y
In Math, prime numbers are whole numbers greater than 1, that have only two factors the number 1 and the number itself.
This program will calculate if a number you enter is prime
Enter a positive whole number to check if it is prime: 1
The definition of a prime number is a positive integer that has exactly two positive divisors.
The number 1 only has one positive divisor, so the number 1 is not prime.
Do you want to run the program again? ('Y' for yes, anything else to quit)
y
In Math, prime numbers are whole numbers greater than 1, that have only two factors the number 1 and the number itself.
This program will calculate if a number you enter is prime
Enter a positive whole number to check if it is prime: 56
This number 56 is not prime
Do you want to run the program again? ('Y' for yes, anything else to quit)
n
Transcribed Image Text:In Math, prime numbers are whole numbers greater than 1, that have only two factors the number 1 and the number itself. This program will calculate if a number you enter is prime Enter a positive whole number to check if it is prime: -1 Value must be a whole number greater than e! Enter a positive whole number to check if it is prime: e Value must be a whole number greater than 0! Enter a positive whole number to check if it is prime: three Value must be a whole number! Enter a positive whole number to check if it is prime: 7 This number 7 is prime Do you want to run the program again? ('Y' for yes, anything else to quit) y In Math, prime numbers are whole numbers greater than 1, that have only two factors the number 1 and the number itself. This program will calculate if a number you enter is prime Enter a positive whole number to check if it is prime: 1 The definition of a prime number is a positive integer that has exactly two positive divisors. The number 1 only has one positive divisor, so the number 1 is not prime. Do you want to run the program again? ('Y' for yes, anything else to quit) y In Math, prime numbers are whole numbers greater than 1, that have only two factors the number 1 and the number itself. This program will calculate if a number you enter is prime Enter a positive whole number to check if it is prime: 56 This number 56 is not prime Do you want to run the program again? ('Y' for yes, anything else to quit) n
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Basic Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education