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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started