Question: Hello I just wanted to know if I explained this python code correctly?: My code: def isitPrime(n): for i in range(2,int(n/2)+1,+1): if n % i

Hello I just wanted to know if I explained this python code correctly?:

My code:

def isitPrime(n): for i in range(2,int(n/2)+1,+1): if n % i == 0: return False return True n = int(input("Enter the number: ")) if isitPrime(n): print("YES") else: print("NO")

My explanation of the code:

The first step in the isitPrime function is that the in the Global Frame isitPrime(n): calls the variable n which states, n = int(input("Enter the number: ")) and then the user inputs their desired number. After the number is inputted it is placed into the Global Frame under the variable n. Then the if else statement begins which states,

if isitPrime(n):

11

print("YES")

12

else:

13

print("NO")

The if else statement needs to print either YES or NO so it calls on the function which states,

1

def isitPrime(n):

2

for i in range(2,int(n/2)+1,+1):

3

if n % i == 0:

4

return False

5

return True

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!