Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions

Question

Create a conceptual framework for a research project.

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago