Error in editing code in Notepad? Why don’t programming beginners use the system text editor? Text editor stepping pit guide, code formatting is invalid, writing code must read

Topic: Write an output that judges the prime numbers between 2 and 10

Environment Left: VScode Right: Windows Text Editor (Notepad)

Table of contents

code display

Original video introduction

Graphic introduction

What's even more outrageous is to use vscode to format with one click, which is bad???

In the end, manually indenting to solve the problem

Solve the problem

So what is the problem?

Just compare the text

Still not intuitive enough, through the text comparison tool

Correct code after manual modification


code display

#错误
for a in range(2, 10):
    for x in range(2, a):
        if a % x == 0:
	    print(a, 'equals', x, '*', a//x)   //出错
	    break   //出错
    else:
    	print(a, 'is a prime number')


#正确
for n in range(2, 10):
    for x in range(2, n):
        if n % x == 0:
            print(n, 'equals', x, '*', n//x)
            break
    else:
        print(n, 'is a prime number')

Original video introduction

Text Editor Error Demo

Graphic introduction

The same piece of code modifies variables, and  spaces are used   as  indents  during editing . If the modification is made in the middle of copying and pasting, the alignment problem will be triggered. The original CV Dafa alignment is outrageous   ???

What's even more outrageous is to use vscode to format with one click, which is bad???

In the end, manually indenting to solve the problem

Solve the problem

So what is the problem?

Note: tab is a tab character rather than an indentation character. Using the habit of "1tab=4" spaces is a bad habit in programming, but editors like IDE/VScode can automatically convert tabs into spaces with one click (eg: ctrl + shift + F in vscode), so solving the problem is the ultimate goal

The guess is that there is a problem with the text characters when writing the code , how to judge?  

Just compare the text

Using word count online statistics (ES JSON online tool),   it can be seen that there are differences between characters and letters

Still not intuitive enough, through the text comparison tool

Use the online text comparison and merging tool (ES JSON online tool) to judge the problem

Correct code after manual modification

Postscript:      Primary editors such as notepad are not recommended for daily use to edit code, only suitable for temporary use, professional code editors are recommended

At the same time, this article is also to tell everyone how to solve the problem when the editor edits the surrogate mother and there is no solution.

Guess you like

Origin blog.csdn.net/qq_41095608/article/details/132587696