1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
KonstantinChe [14]
4 years ago
9

Define a function is_prime that receives an integer argument and returns true if the argument is a prime number and otherwise re

turns false. (An integer is prime if it is greater than 1 and cannot be divided evenly [with no remainder] other than by itself and one. For example, 15 is not prime because it can be divided by 3 or 5 with no remainder. 13 is prime because only 1 and 13 divide it with no remainder.) This function may be written with a for loop, a while loop or using recursion. Use the up or down arrow keys to change the height.
Computers and Technology
1 answer:
qaws [65]4 years ago
5 0

Answer:

<em>This function (along with the main)is written using python progrmming language.</em>

<em>The function is written using for loop; </em>

<em>This program does not make use comments (See explanation section for detailed line by line explanation)</em>

<em></em>

def is_prime(num):

    if num == 1:

         print(str(num)+" is not prime")

    else:

         for i in range(2 , num):

              if num % i == 0:

                   print(str(num)+" is not prime because it can b divided by "+str(i)+" and "+str(int(num/i))+" with no remainder")

                   break;

         else:

              print(str(num) + " is prime because only 1 and "+str(num)+" divide it with no remainder")

num = int(input("Number: "))

is_prime(num)

Explanation:

This line defines the function is_prime

def is_prime(num):

The italicize line checks if the user input is 1; If yes it prints 1 is not prime

<em>     if num == 1: </em>

<em>          print(str(num)+" is not prime") </em>

If the above conditional statement is not true (i.e. if user input is greater than 1), the following is executed

    else:

The italicized checks if user input is primer (by using for loop iteration which starts from 2 and ends at the input number)

         <em>for i in range(2 , num): </em>

<em>               if num % i == 0: </em>

<em>This line prints if the number is not a prime number and why it's not a prime number</em>

<em>                    print(str(num)+" is not prime because it can b divided by "+str(i)+" and "+str(int(num/i))+" with no remainder") </em>

<em>                    break; </em>

If otherwise; i.e if user input is prime, the following italicized statements are executed

         <em>else: </em>

<em>               print(str(num) + " is prime because only 1 and "+str(num)+" divide it with no remainder") </em>

<em>The function ends here</em>

The main begins here

num = int(input("Number: "))  This line prompts user for input

is_prime(num) This line calls the defined function

You might be interested in
On the following page, write a static method print Short Words that accepts two parameters:_____.
barxatty [35]

Methods in Java are collections of program statements that are named, and executed when called/invoked

The printShortWords method in Java where comments are used to explain each line is as follows:

//This defines the static method

public static void printShortWords(String str, int maxLength){

    //This iterates through each word in the string

    for(String word: str.split(" ")){

        //The compares the length of each word to maxLength

        if(word.length()<=maxLength){

            //If the length of the current word is atleast maxLength, the word is printed

        System.out.print(word+" ");

        }

    }

}

Read more about static methods at:

brainly.com/question/19360941

7 0
2 years ago
The Tab dialog box helps you set tabs in your word processing document. What does this dialog box control the movement of when y
Nata [24]
<span> What does this dialog box control the movement of when you press the tab key?
answer: cursor
but im not 100% sure so sorry if I get you the wrong answer :/ </span>
8 0
3 years ago
Read 2 more answers
7d2b:00a9:a0c4:0000:a772:00fd:a523:0358
motikmotik

Answer:

yh3iuskjldnsjfhbcgfihekwfhei3wh8hfefbgp

Explanation:

6 0
3 years ago
Differentiate between inherited trait and acquired trait​
miskamm [114]

Answer: Inherited trait is something you already have and acquired is something that you learn or achieve.

Explanation:

8 0
3 years ago
Match the example with the type of collection.
labwork [276]

Answer:

1.c

2.list

3.tuple

Explanation:

5 0
3 years ago
Other questions:
  • Please Help Me!!! 40 Points!! Match the correct definition to each term
    14·1 answer
  • On five lane roadways, the center lane is designated for __________ and is used by vehicles traveling in both directions.
    14·1 answer
  • Consider the following 32 bit binary representation of the value using IEEE 754 single precision floating point representation.
    15·1 answer
  • Which of these is NOT a reason why you would print handouts of your presentation?
    14·1 answer
  • Which type of programming language is understood directly by the computer? Assembly language Machine language Visual Basic Java
    13·1 answer
  • The addresses a program may use to reference memory are distinguished from the addresses the memory system uses to identify phys
    15·1 answer
  • Your computer has been showing signs of a malware infection, and today it started up in Safe Mode. Because your computer is not
    6·1 answer
  • As with most professions, photography comes with its own unique set of terms and jargon. Identify at least four different words
    5·1 answer
  • Write a program with the total change amount as an integer input, and output the change using the fewest coins, one coin type pe
    13·1 answer
  • How much would you guys pay for a used ps4 with a black ops 3 disc?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!