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
It’s illegal to hack into a system without authorization, but is it ethical for a gray-hat to hack into a system if the intent i
oksian1 [2.3K]

Answer:

Some hackers are smart about there hacking .. others have a a plot but didnt test there theory

Explanation:

8 0
3 years ago
Describe email etiquette and netiquette when communicating electronically.
navik [9.2K]

Answer:

Email etiquette refers to the principles of behavior that one should use when writing or answering email messages. It is also known as the code of conduct for email communication. Email etiquette depends upon to whom we are writing- Friends & Relatives, Partners, Customers, Superior or Subordinates

Difference Between Etiquette and Netiquette is that Etiquette is the simple requirements needs for social behavior while Netiquette, is the code of acceptable behaviors users should follow while on the Internet.

6 0
3 years ago
How important are operating system in our devices?​
TiliK225 [7]

Answer:

Explanation:

An operating system is the most important software that runs on a computer. ... It also allows you to communicate with the computer without knowing how to speak the computer's language. Without an operating system, a computer is useless.

6 0
2 years ago
Read 2 more answers
For successful completion of an 8-Week course, how often should I visit the course web site to check for new e-mail and any inst
Brilliant_brown [7]

Answer: The course web should be visited daily to check for new e-mail and any instructor announcement.

Explanation:

For any serious-minded and Intellectually inclined individual, who aimed for a successful completion of an 8-Week course, it's imperative for him/her to visit the course web site daily to check for new e-mail and any instructor announcements.

8 0
3 years ago
When creating an electronic slide presentation, Lee should avoid
Amanda [17]

I believe the answer is <u>Using sound effects between slides.</u>

Using sound effects between slides can cause for a distraction, and if you are in college, your professor may not score your presentation as well as if it were made without sound effects. Hope this helps!

5 0
3 years ago
Other questions:
  • Write the printitem() method for the base class. sample output for below program: last name: smith first and last name: bill jon
    6·2 answers
  • How is steering different from turning ? Need help //:
    13·1 answer
  • g Write a program that prompts the user to enter two integers. The program outputs how many numbers are multiples of 3 and how m
    11·1 answer
  • What is malware short for?
    13·2 answers
  • Which software is used for cover letters and resumes
    9·2 answers
  • Which of the following illustrations is depicted in the icon that's used to access Windows Help and Support files?
    13·1 answer
  • Which is said to be ‘computer on a chip’ (a) Micro processors (b) Microcontrollers (c) Both (c) None of the above
    9·1 answer
  • What is one reason you might want to change your document's margins
    12·1 answer
  • Determine the distance between point (x1, y1) and point (x2, y2), and assign the result to points Distance. The calculation is:
    12·1 answer
  • Name 6 examples of how telemedicine is used in healthcare
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!