Set conditional breakpoints in python program debugging

People who are new to programming often don't have a deep understanding of the debugging code, and feel that the function is done. Once there is a problem with the program, there is no way to start. In actual development, debugging code usually takes more time than writing new code.

Therefore, choosing a reasonable debugging method and tools is of great significance for development.

When writing Python code, the debugging method I am used to is very simple, is to increase the output in the program, in order to understand the running path of the program and the value of the variable.

Take the following code as an example:

Deftwice(n):

n*=2

Returnn

a=input("a:")

b=input("b:")

Ifa"3:

b+=4

Ifb"5:

c=a+twice(b)

Else:

c=twice(a)+b

Else:

B-=2

Ifb "1:

c=a-twice(b)

Else:

c=twice(a)-b

Printc

Even if this is not a long piece of code, if for some inputs, the final output value is inconsistent with your expectations, it is not obvious to see from the naked eye what went wrong.

So I will add some auxiliary code:

Deftwice(n):

n*=2

Returnn

a=input("a:")

b=input("b:")

Print "====a,b:",a,b

Ifa"3:

b+=4

Print "====1b:",b

Ifb"5:

c=a+twice(b)

Print "====1c:",c

Else:

c=twice(a)+b

Print "====2c:",c

Else:

B-=2

Print "====2b:",b

Ifb "1:

c=a-twice(b)

Print "====3c:",c

Else:

c=twice(a)-b

Print "====4c:",c

Printc

After the effect:

a: 2

b:4

====a,b:24

====2b: 2

====4c:2

2

By adding similar output content, you can clearly understand the running status of the program.

Outdoor Small Energy Storage System

Portable power supply humanized output port design: AC dual output port 220V output, to solve multi-channel power demand; DC 24V, 12V cigarette lighter, dual 5V USB output, more widely used. Can meet the needs of most electrical appliances, such as energy storage system for LED Light,energy storage system for outdoor, energy storage system for medical equipment,mobile phones, telephones, digital cameras, mobile hard drives, digital cameras, tablets, laptops, car starters, pumps, postal and telecommunications, environmental instruments Etc; can also be used in the following areas such as: finance, first aid, excavation, exploration, military, science, media, tourism, disaster relief, medical assistance, environmental protection and areas with widespread power shortages.

Solar Storage Battery,Small Solar System,Energy Storage System For Computer,Energy Storage System For Power Tools,Portable Small Electric Station,Multifunctional Lithium Generator

Shenzhen Enershare Technology Co.,Ltd , https://www.enersharepower.com