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
vichka [17]
3 years ago
6

Write a program in python to test if given number is prime or not.

Computers and Technology
2 answers:
Lerok [7]3 years ago
7 0

num = int(input("Enter a number to test if it's prime or not: "))

if num%2 == 0:

   if num == 2:

       print(num,"is prime")

   else:

       print(num,"is not prime")

else:

   count = 0

   for x in range(2,num):

       if num % x == 0:

           count+=1

   if count==0:

       print(num,"is prime")

   else:

       print(num,"is not prime")

I wrote my code in python 3.8. I hope this helps!

Paraphin [41]3 years ago
4 0

Answer:

Answer:

def main():

num = int(input("Input a number to check for prime: "))

if num > 1:

 for i in range(2,num):

  if (num % i) == 0:

   print("%d is not a prime number" % num)

   break

  else:

   print("%d is a prime number" % num)

   break

else:

 print("%d is not a prime number" % num)

 

if __name__ == "__main__":

main()

Explanation:

Solution retrieved from programiz.com.

Note, this program uses the idea of the Sieve of Eratosthenes to validate the input number by using the modulo operator to determine primeness.

The program will output to the user if the number input is indeed prime or not.

Cheers.

Explanation:

You might be interested in
What is the difference between a fragment shader and vertex shader? How do they relate?
Inessa05 [86]

Answer:

vertex  shader is performed, while on each pixel,  fragment shader is achieved. The shader fragment is implemented after the implementation of shader vertex

Explanation:

A shader fragment is the same as a shader for pixels.

A major distinction is that a shader of the vertex can alter the vertices characteristics. whixch are the end points of polygon

On the other side, the fragment shader is responsible for the display of the pixels between the vertices. They are interpolated by particular guidelines between the specified vertices.

On each vertex, vertex  shader is performed, while on each pixel,  fragment shader is achieved. The shader fragment is implemented after the implementation of shader vertex

5 0
3 years ago
For her homework, Annie has added the picture of a fruit in a document. She wants to enhance it to give a cut-out look. Which fe
Kaylis [27]

Answer:

Explanation:

We must follow several steps:

  1. We must click in the image
  2. Click Image Tools > Format
  3. Click the date under Crop
  4. We must resize the image, or Trim one side, Trim two adjacent sides, Trim the same fragment.
  5. Click the Crop button again if you finished

In addition, we can change the form of the image, we have a lot of options in crop to shape.

8 0
3 years ago
Read 2 more answers
Code works, need help writing header file.
vovikov84 [41]

Answer:

kbfbnmcj hbx nmjn mz kjn  mj     hk hhhhhhgdhggbddddddbvgfcgfctrctgvhyubujbnjinkikmokimloplkmkojihgftrdesw3l,kmjinhuygtfrde4sw34drftyghuijokkkkkkkkkkkkkkkijjjjjjjkopl[[[[[koiju98hytttttttttttttuhiouhygdtrsgyuihkl;;ihugydtrcfbhjklioutrcgfbhjkloiuytdrhjukliuytrdgfhjkiouy7gfhjklpoiudtrkhjl;[poiughjbnm,;lkihuygtfvbnmjkiuytfgchvbnmkjlhuygfdc vbnhnjkygtdsfxghbjkiuhytrdgfhjuioytrdfgchbnmkloiuytfdfghjiouyyyyyyhjkpoi8u97t6rdghjuo0987hjklpo0i98uyghjbkopiuyhjbnkploiuhyjbnmkloiuhygbvjnmk,l;oipuhgbjkn mjhuygfvbnhjkiouuuukjopipkjmloiujoklm;okjm,kloiuhjnmkiuhjbkiuygfhuji8yghyugfvhjkjiuhygfhuijokpiuyt67u89poiuhygftduhjklphuytfrdesdtgyuhi;lkyuuuugij'[;;;;;;;;;;;;;;;;;;;;okpuuuutyyyyy[poiudtryuiop[;oiudtrruiooooooooytg[pl;oiuhygtfffkjjjjhugvcfxkml,;kjnhbgvchbjnk,lijuhygfcbvh nmmpoiugyhjb,m ./[poiuhbjnm,k;lijuytfrcgbvhkjlipouuuujipouuuukliouygkjliubhjkml

Explanation:

7 0
3 years ago
Write a class called Line that represents a line segment between two Points. Your Line objects should have the following methods
mel-nik [20]

Answer:

import java.awt.Point;

public class Line{

private Point point1, point2;

public Line(Point p1, Point p2){

point1 = p1;

point2 = p2;

}

public Point getP1(){

return point1;

}

public Point getP2(){

return point2;

}

public String toString(){

return "[( The " + point1.x + "," + point1.y + "), (" + point2.x + "," + point2.y +")]";

}

public static void main(String args[]){

Line lineObj = new Line(new Point(7,9), new Point(6,2));

System.out.println(lineObj.toString());

}

}

Explanation:

  • Declare the points inside the class Line.
  • Initialize the getters and setters method for the class.
  • Define a toString method that returns the information in a formatted manner.
  • Inside the main method, initialize an object with some values.
  • Display the information by calling the toString method.
4 0
3 years ago
Which of the following topics is too broad for a 10-minute speech? A. classes offered in interior design B. the history of moder
aksik [14]
I would say it is <span> B. the history of modern interior design 
Because this subject stretches pretty far into history</span>
3 0
3 years ago
Read 2 more answers
Other questions:
  • The section called Breaking Substitution Ciphers (p. 166) describes a "random substitution cipher," in which each letter of the
    11·1 answer
  • Your organization issues devices to employees. These devices generate one-time passwords every 60 seconds. A server hosted withi
    15·1 answer
  • How can you efficiently restrict the read-only function of a requesting SNMP management station based on the IP address?
    14·1 answer
  • Write a program that will print out statistics for eight coin tosses. The user will input either an "h" for heads or a "t" for t
    14·1 answer
  • Why is it important to evaluate the website on which you plan to shop?
    7·2 answers
  • The show ip dhcp binding command displays _____. (Points : 5) the MAC table cache information
    7·1 answer
  • What is the output of the following program?
    11·1 answer
  • Ask the user to input a word. Then, print the first letter, the last letter, and the length of the word on the same line with no
    6·1 answer
  • Why do you want to work for Rev?
    5·1 answer
  • a cloud access security broker (casb) provides protection across 4 areas/pillars: visibility to detect all cloud services, data
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!