You are given a function called is_prime  which consumes a positive number and returns True if the number is prime and False if the number is not prime.  You do not need to write the is_prime function - it is already pre-defined.Your task is to use the Design Recipe to write a main function, that consumes no parameters, which prompts the user for a positive integer, n, and displays the first n primes. Your main function should call the is_prime function. Include a docstring!

Question
Asked Oct 16, 2019
192 views

You are given a function called is_prime  which consumes a positive number and returns True if the number is prime and False if the number is not prime.  You do not need to write the is_prime function - it is already pre-defined.

Your task is to use the Design Recipe to write a main function, that consumes no parameters, which prompts the user for a positive integer, n, and displays the first primes. Your main function should call the is_prime function. Include a docstring!

check_circle

Expert Answer

Step 1

Before solving this question first, you should know some functions definitions :

Prime number: Primary numbers are two-factor numbers, one and the number itself. The two variables could split it equally. For example, 7 is a prime number that can be divided by only 1 and 7.If we divide 7 by any other number, a fraction value will be  generated. A composite number, which has more than two variables, is the contradictory component of a prime number. We have encountered many types of numbers in   the number system, the most important of which are prime and composite numbers.

isprime():This simple function isprime(number) checks whether the number given is a prime number and returns either True or False? The method guarantees that the number is a positive integer and that 1 is not a prime number?

range():The function range is a builtin function in Python and returns an object of range. 

counter: A counter is a container that records how many times it adds identical values.

So following variables , strings , functions are used to solve this problem:

Variables: i , n

Functions: range() , str() , main() .

Step 2

Following steps, a user must be followed to print the prime number:

  1. Taking the input from the user.
  2. Check whether the input is prime or not.
  3. Taking the range function to print the number till user enter the value.
  4. Print the numbers of primes numbers only contains po...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: How do i solve this problem in python? ( has 3 steps)

A: NOTE:The given information is incomplete (Formula to calculate the minutes to walk or run for a give...

question_answer

Q: C++ Language

A: Create the main method in the C++ program and define all required variables to solve the problem.ini...

question_answer

Q: What is out put?

A: Output:Output is the value produced on the system based on the input supplied by the user.

question_answer

Q: Assume that a double variable named alpha contains the value of an angle in radians. Compose a C++ s...

A: Below program uses following c++ functionsstd::setw, std:setfill, setprecision(int n) defined under ...

question_answer

Q: Write a program that reads in a tax rate (in percentage) and the prices of three items from the keyb...

A: Program AlgorithmDeclare the required variables in the main().Get the input from user for tax rate, ...

question_answer

Q: Can someone help me on solving this? Thank you!

A: For loop:A loop is used repeatedly to execute a sequence of statements until a given condition is fu...

question_answer

Q: Write a Java program that prompts the user to enter a password and checks whether it is valid accord...

A: Create a main() method and a check_pass() to validate whether a password contains 8 characters or no...

question_answer

Q: Please explain how you solve the follwing problem:

A: The context free grammar is given below. To convert it into Chomsky normal form, some rules must be ...

question_answer

Q: 3prep Write a Python program for an online MoonBucks coffee order. Coffee is sold by the pound, and ...

A: Program AlgorithmDeclare the required variables and take the input from the user for the pound’s use...