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
A developer wants to take existing code written by another person and add some features specific to their needs. Which of the fo
anzhelika [568]

Answer:

open-source

Explanation:

open-souce software allows any user to submit modifications of the source code

7 0
2 years ago
What is the output of the following code segment?
Aliun [14]

Answer:

o

Explanation:

8 0
2 years ago
Given the number of rows and the number of columns, write nested loops to print a rectangle. (PYTHON)
Allushta [10]

Answer:

Explanation:

Please see the attached picture for help.

6 0
3 years ago
Read 2 more answers
You are configuring a wireless network with two wireless access points. Both access points connect to the same wired network. Yo
krok68 [10]

Answer:

have the same SSID but different channels

Explanation:

Based on the information provided within the question it can be said that the best option to accomplish this would be to have the same SSID but different channels. This would maintain the users connected to the same network name (SSID) but still be able to roam and jump from one access point to the other.

7 0
3 years ago
Read 2 more answers
How can you get in touch with someone when they ain't answering you ☹
mixer [17]
You can go to their house and talk to them
3 0
3 years ago
Other questions:
  • An online service provider provides its users with hosted computers, an operating system, and a database management system (DBMS
    12·1 answer
  • What is the formula equivalent to the function =SUM(B1:B5)? A. =B1+B5 B. =$B$1+$B$5 C. =B1+B2+B3+B4+B5 D. =$B$1+$B$2+$B$3+$B$4+$
    7·1 answer
  • Write a method called printRange that accepts two integers as arguments and prints the sequence of numbers between the two argum
    6·1 answer
  • To read visual and audio text means
    11·1 answer
  • A _______ is conducted to determine the adequacy of system controls, ensure compliance with established security policy and proc
    10·1 answer
  • A folder has been shared with other users and set to read-only. What does this mean for users?
    12·2 answers
  • This is your code.
    9·1 answer
  • Which of the following class definition defines a legal abstract class Group of answer choices public class Rectangle abstract {
    15·1 answer
  • Would you consider upgrading Maxine’s wardrobe a need or a want?
    11·1 answer
  • Which of the following is used to store data in the computer's memory that can be
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!