Python- find a bug (error) ways and means to resolve

Copyright: Without permission, please do not reprint without permission! ! ! https://blog.csdn.net/weixin_44755148/article/details/90236043

bug information to see how the message

1, line 2 on behalf of the bug appears in the second line, so when we Debug can preferentially start checking from the second line
2, ^ position represents bug occurred here that position is the end of the second row
3, this line I wrote the wrong type, SyntaxError refers to the grammatical errors
Here Insert Picture Description

Several handling of the bug

bug1: careless

Here Insert Picture Description

bug2: knowledge unskilled

Here Insert Picture Description
Here Insert Picture Description

bug3: code logic is not clear

Here Insert Picture Description

bug4: Passive out of the pit (here we use exception handling (try ... except ...))

Here Insert Picture Description
Here Insert Picture Description

#当有多个异常,我们可以这样写(将两个(或多个)异常放在一起,只要触发其中一个,就执行所包含的代码。)
except(ZeroDivisionError,ValueError):
         #print('你的输入有误,请重新输入!')

#常规错误的基类,假设不想提供很精细的提示,可以用这个语句响应常规错误
except Exception:
        print('你的输入有误,请重新输入!')

Guess you like

Origin blog.csdn.net/weixin_44755148/article/details/90236043