Ask Question

A prime number is an integer that is greater than 1 and that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6. Write a function name isPrime, which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise. Demonstrate the function in a complete program that prompts for a number and indicates whether or not it is prime.

+5
Answers (1)
  1. 1 March, 15:23
    0
    def Isprime (number):

    if number>1:

    for i in range (2, number):

    if (number % i) = = 0:

    print (number, "is not a prime number")

    break

    else:

    print (number, "is a prime number")

    else:

    print (number, "is not a prime number")

    x = Isprime (5)

    y = Isprime (17)

    z = Isprime (14)

    Explanation:

    A prime number is a number that can only be divided by 1 and itself. Prime number includes 5, 7, 11 etc.

    def Isprime (number) : A function is created Isprime and the argument number is used.

    if number>1 : if the number is greater than 1.

    for i in range (2, number) : This expression loop through 2 to the number (argument)

    if (number % i) = = 0: If the number divided by the looped value is equal to zero.

    print (number, "is not a prime number") print the number is not a prime number

    break This means stop and go back to the loop

    else: otherwise

    print (number, "is a prime number") Print the number is a prime number.

    else: This else is under the first if statement.

    print (number, "is not a prime number") print the number is not a prime number.

    x = Isprime (5)

    y = Isprime (17)

    z = Isprime (14)

    These call the function with the argument.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “A prime number is an integer that is greater than 1 and that is only evenly divisible by itself and 1. For example, the number 5 is prime ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers