Answer to Question #335752 in Python for Elle Joy

Question #335752

Elle Joy Vasquez


Preliminary Test 01


Create a Python function that takes a number as a parameter and check the number is PRIME or NOT.


Note: A prime number (or a prime) is a natural number greater than 1 and that has no positive divisors other than 1 and itself.

1
Expert's answer
2022-04-30T05:39:27-0400
def prime(num):
    if num > 1:
        for i in range(2, int(num/2)+1):
            if (num % i) == 0:
                print(num, "is not a prime number")
                break
        else:
            print(num, "is a prime number")
    else:
        print(num, "is not a prime number")


number = int(input("Enter number: "))
prime(number)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS