90 096
Assignments Done
99.4%
Successfully Done
In September 2020

# Answer to Question #50999 in Python for Will

Question #50999
Given a positive integer n , assign True to is_prime if n has no factors other than 1 and itself. (Remember, m is a factor of n if m divides n evenly.)
1
2015-02-27T05:10:42-0500
#!/usr/bin/python
import math
# Question #50999, Programming, Python
# Given a positive integer n, assign True to is_prime
# if n has no factors other than 1 and itself.
# (Remember, m is a factor of n if m divides n evenly.)
n = input(&quot;Enter a number: &quot;)
# The method of checking whether a number is prime or not.
# Divide n by all numbers from 2 to square_root(n).
# If n is not divisible by neither of those numbers, then n is a prime number
# Othervise n is not a prime number
# compute square root of n, remove fractional part to get an integer number
sqrtn = int(math.sqrt(n))
is_prime = True # set initial value for is_prime
for i in range(2,sqrtn+1):
if (n % i) == 0: # check if n is divisible by i
is_prime = False # change value of is_prime
break # exit loop
if is_prime:
print n, &quot;is a prime number&quot;
else:
print n, &quot;is not a prime number&quot;
﻿

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!