In Pycharm, when editing a program, often the code is correct, but do not know where the error, here in the following example to illustrate the importance of code format in the Pycharm.
Title: Write a function, accept a positive even number as a parameter, output 2 prime numbers, and the sum of these 2 primes equals the original positive even, there are many groups of eligible primes, then all output.
Import Math
def isprime (n):
m=int (MATH.SQRT (n)) +1 for
i in range (2,m):
if n%i==0:
return False return
True
def judge (N):
if Isinstance (n,int) and n>0 and n%2==0:
for I in range (3, int (n /2) +1):
if I%2==1 and IsPrime (i) and IsPrime (n-i):
print (i, ' + ', n-i, ' = ', n)
judge (80)
Results The error is shown below;
D:\learn\python\python.exe d:/learn/code/myfirstpython.py
File "d:/learn/code/myfirstpython.py", line 11
For I in range (3, int (N/2) +1):
^
Indentationerror:unindent does not match no outer indentation level
Process finished with exit code 1
After modification, move the For statement in the judge function to the previous if statement. This is because the for statement is to be processed by the IF statement, noting ":" after the IF statement.
As shown in the following illustration:
Import Math
def isprime (n):
m=int (MATH.SQRT (n)) +1 for
i in range (2,m):
if n%i==0:
return False return
True
def judge (N):
if Isinstance (n,int) and n>0 and n%2==0:
for I in range (3, int (n /2) +1):
if I%2==1 and IsPrime (i) and IsPrime (n-i):
print (i, ' + ', n-i, ' = ', n)
judge (80)
D:\learn\python\python.exe d:/learn/code/myfirstpython.py
5 + 75 = 80
7 + 73 = 80
9 + 71 = 80
11 + 69 = 80
13 + 67 = 80
15 + 65 = 80
17 + 63 = 80
19 + 61 = 80
21 + 59 = 80
23 + 57 = 80
25 + 55 = 80
27 + 53 = 80
29 + 51 = 80
31 + 49 = 80
33 + 47 = 80
35 + 45 = 80
37 + 43 = 80
39 + 41 = 80
Process finished with exit code 0
This prompts us to use pycharm in the future to write the format problem. Details determine success or failure.