How would you write main() as specified in the img below? This is what I have written(and it works) but it does not meet the requirments asked to have in main(), and likewise of determine_prime() as the actual text string should be produced in main(); 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.")      print("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):      if isWhole < 2: # catch 1 and anything less than zero          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.")      else:          prime = True          for i in range(2, isWhole):              if isWhole%i == 0:                  print("This number", isWhole,"is not prime")                  prime = False                  break          if prime:              print("This number", isWhole,"is prime")              return isWhole def main():      get_intro()      isWhole = validate_input()      determine_prime(isWhole)      do_again() def do_again():      print("Do you want to run the program again? ('Y' for yes, anything else to quit.)")      cont = input() # Start cont = "Y" while cont == "Y": main()

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%

How would you write main() as specified in the img below?
This is what I have written(and it works) but it does not meet the requirments asked to have in main(), and likewise of determine_prime() as the actual text string should be produced in main();

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.")
     print("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):
     if isWhole < 2: # catch 1 and anything less than zero
         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.")
     else:
         prime = True
         for i in range(2, isWhole):
             if isWhole%i == 0:
                 print("This number", isWhole,"is not prime")
                 prime = False
                 break
         if prime:
             print("This number", isWhole,"is prime")

             return isWhole
def main():
     get_intro()
     isWhole = validate_input()
     determine_prime(isWhole)
     do_again()

def do_again():
     print("Do you want to run the program again? ('Y' for yes, anything else to quit.)")
     cont = input()

# Start
cont = "Y"
while cont == "Y":
main()

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
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()
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Binary numbers
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