In cryptography, it is important to use prime numbers. Write a function is_prime that has a parameter num and returns True if the number num is prime or False if not. A number num is prime if there does not exist a number, say x, which is between 2 and the number (not including the number) and evenly divides into number num. Note that if a number num is evenly divisible by number x that num % x will be zero. Suggest using a for x in range loop and return False as soon as a number is encountered that evenly divides into num. Only after testing that all numbers between 2 and num (exclusive of num) do not evenly divide into num should the function return True. Continuing with the theme of cryptography, we now want to provide a function get_primes_between that is passed parameters n, min_value, and max_value that will return a list of n numbers of randomly chosen values between min_value and max_value. The numbers in the returned list must be unique (i.e. no duplicates) . Python provides a function randint in module random that can be used to get a random number between two values passed as arguments. get_primes_between can use randint to randomly choose a number. Furthermore, is_prime function from the previous question can be used to test if the randomly chosen number is a prime number (you can assume is_prime is written and can be called - do not need an import statement). Suggest defining an empty list, then use a loop that will loop until there are n elements in the list. In the body of the loop randomly choose a number, test if the number is prime, and if so append the number to the list. However, do not append the number if it is already in the list. Return the list after the loop. Function get_primes_between must also validate the values of the parameters. If any of the parameters are negative return the message 'Invalid value - parameter cannot be negative'. Furthermore, min_value cannot be 0 or even 1. In such case return the message 'Invalid value - min_value must be greater than 1'. Lastly, max_value must be greater than min_value. If not return the message 'Invalid value - max_value must be greater than min_value'. Write the function get_primes_between.

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

In cryptography, it is important to use prime numbers. Write a function is_prime that has a parameter num and returns True if the number num is prime or False if not. A number num is prime if there does not exist a number, say x, which is between 2 and the number (not including the number) and evenly divides into number num. Note that if a number num is evenly divisible by number x that num % x will be zero. Suggest using a for x in range loop and return False as soon as a number is encountered that evenly divides into num. Only after testing that all numbers between 2 and num (exclusive of num) do not evenly divide into num should the function return True.

Continuing with the theme of cryptography, we now want to provide a function get_primes_between that is passed parameters n, min_value, and max_value that will return a list of n numbers of randomly chosen values between min_value and max_value. The numbers in the returned list must be unique (i.e. no duplicates) .

Python provides a function randint in module random that can be used to get a random number between two values passed as arguments. get_primes_between can use randint to randomly choose a number. Furthermore, is_prime function from the previous question can be used to test if the randomly chosen number is a prime number (you can assume is_prime is written and can be called - do not need an import statement). Suggest defining an empty list, then use a loop that will loop until there are n elements in the list. In the body of the loop randomly choose a number, test if the number is prime, and if so append the number to the list. However, do not append the number if it is already in the list. Return the list after the loop.

Function get_primes_between must also validate the values of the parameters. If any of the parameters are negative return the message 'Invalid value - parameter cannot be negative'. Furthermore, min_value cannot be 0 or even 1. In such case return the message 'Invalid value - min_value must be greater than 1'. Lastly, max_value must be greater than min_value. If not return the message 'Invalid value - max_value must be greater than min_value'.

Write the function get_primes_between.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Function Arguments
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