please read the details and answer everything. I wanna see full answer do not sk
ID: 3624639 • Letter: P
Question
please read the details and answer everything. I wanna see full answer do not skip anything let me know if you have anyquestionPython Code
Prime Numbers
a prime number is a number that is only evenly divisible by itself and 1. for example, the number 5 is prime because it can only by 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.
design a boolean function named isPrime which takes an integer as an argument and returns True if the argument is a prime number or False otherwise. Use the function in a program that prompts the user to enter a number and then display a message indicating whether the number is prime.
For 10 extra credit points, add to the problem definition that the program is to process as many number as the use wants to enter. Use a question and answer to detemine if the user wants to process another number or to end the program
Explanation / Answer
import sys
def isprime(n):
if n == 2:
return 1
if n % 2 == 0:
return 0
max = n**0.5+1
i = 3
while i <= max:
if n % i == 0:
return 0
i+=2
return 1
while True:
n = int(input(' plz enter number :'));
if isprime(n):
print "%d is prime" % n
else:
print "%d is not prime" % n
b = raw_input('want to check for one more number? (y/n)')
if b!="y" and b!="Y":
break;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.