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]
2 years ago
6

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

Computers and Technology
2 answers:
Lerok [7]2 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]2 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
How many digits are in the binary number system? Explain why.
Katen [24]

Answer:

Since there are only two digits in binary, there are only two possible outcomes of each partial multiplication: If the digit in B is 0, the partial product is also 0. If the digit in B is 1, the partial product is equal to A.

Explanation:

8 0
2 years ago
Read 2 more answers
During which part of geologic time were dinosaurs most common?
ANTONII [103]
The answer is C. Jurassic.
6 0
3 years ago
Read 2 more answers
Why do amusement parks continue to build new roller coasters?
kykrilka [37]
They do it because they want people to experience new rides, instead of the same old boring rides they’ve been on several times.
5 0
3 years ago
Read 2 more answers
A cookie is.... a. an illegal use of information about a customer b. a feature of a Web site designed to attract children c. a f
Elodia [21]

Answer:

C. A file that a Web site stores on a visitor's computer

Explanation:

Have a nice day! :)

3 0
2 years ago
Which type of software is created on user dimension​
Ratling [72]

Answer:

Application and system software is created on user dimension.

6 0
2 years ago
Other questions:
  • Which statement prints "hi" on the screen?
    5·2 answers
  • Containers for contaminated sharps must have several characteristics. What’s missing from the list? PuContainers for contaminate
    5·2 answers
  • Meaning of page break​
    8·1 answer
  • What are the seven internal compontents of a computer
    10·1 answer
  • Who created apple and in what year was it created
    9·2 answers
  • What is sum after the following loop terminates? int sum = 0; int item = 0; do { item ; sum = item; if (sum > 4) break; } whi
    8·2 answers
  • PLEASE HELP
    14·1 answer
  • HELP ME PLEASE ASAP
    6·1 answer
  • For this activity, you will practice being both proactive and reactive to bugs. Both are necessary to get rid of errors in code.
    5·1 answer
  • Question 2 of 25
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!