Quote:
Hi, I'm just stuck in solving this number guess game program. I was given the program to correct
Being able to correct other's code is a key skill for a programmer.
You will get this skill by practicing, and the more you practice, the better you get.
So you are told there is a bug:
First thing, run the program and see where the language chocks. It tells you where the source code is not Python anymore.
Then read the code at position of error and see if you find something wrong. If you don't find, read again very carefully.
If you don't find again, retype the line of code in another place and then insert it near the offending line.
compare original line with you own line, is there something different ? (in this case, it should be something different)
Sometimes, the problem is in the logic, in this case, the debugger is the tool of choice.
There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.
Debugger - Wikipedia, the free encyclopedia[
^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[
^]
Basic Debugging with Visual Studio 2010 - YouTube[
^]
27.3. pdb — The Python Debugger — Python 3.6.1 documentation[
^]
Debugging in Python | Python Conquers The Universe[
^]
pdb – Interactive Debugger - Python Module of the Week[
^]
The debugger is here to only show you what your code is doing and your task is to compare with what it should do.