Simple rules to follow when posting on forums in regards to debugging your code:
1) If your posting more than about 10 lines of code to illistrate your problem, then you are going to piss people off. Why? Because no one wants to review a hundred lines of code to find the problem. You are the one that created the code, so you know it best.
2) Isolate the problem. How? The Traceback error. It will indicate the name of the error and the line the error is found. If the error is within the definition of a function, then post that section of the function. Sometimes you may also have to post the function call also. And always post the entire traceback error.
3) When explaining the error, get to the point. Don't make an essay about it.
4) Google it. Copy and paste the last line of the traceback error into google. Many times people have had the same error you have had. Where many people have answered and solved it already.
This is a simple traceback error example.
1st line: Indicates that it is an error.
2nd line: shows the file or module the error is located in.
3rd line: is the exact line of code that caused the error.
4th line: Is the description of the error. It tells us it is an AttributeError, and that the object does not have that attribute.
Without even seeing the code the traceback error says it all in this case.
My line of code is valid, but I get a Traceback error for it?
Some Traceback errors are more complicated. The line of code that it shows as an error is valid. But you have to dig deeper. Think backwards. Let's take this code for example:
Each line of code here is valid, but the manner that they are all together are not.
1st line: creates a list with 2 indexes in it, the strings 'a', and 'b'
2nd line: pops the last index out of the list
3rd line: attempts to print the second index of the list 'b'
Now we get the traceback:
Now this does not mean that we typed the line of code print(lister[1]) wrong. It means that index of that list no longer exists. Even though we created that index, pop() took the last index of the list off and now we are trying to print an index of a list that no longer exists, giving us the error.
Even though this is simple, more complex problems can relate to this as the line of code that the error shows is not the direct problem.
The steps of finding this error:
1) Why is it not able to print?
2) What is it trying to print?
3) Any typo?
4) What makes the lists index out of range?
5) What affects that list previously of trying to print it?
Which will eventually lead you to the fact that you either need to not pop it, create a new index for it to print, or change the index of the list that it is trying to print.
Posting this on the forums
Now let's say you had this within a hundred lines of code, and you could not figure out the description of the traceback error. You would not post the entire hundred lines of code on the forums. Even as simple as it is, no one would look at it because no one would want to skim all those lines of code. You also don't want to just post the traceback and the line of the error that cause it, because then you are not giving enough information of what is affecting that list. In this situation posting the creation of the list, the line that affects the list, the print attempt of the list, and the traceback will give a small amount of code for the users to look at and find the answer to your problem, instead of them weaving through hundreds of lines of code to find it. Now you only posted a readble 7 lines of code. Post smart.
Avoiding massive elif statements
the first example shows elif statments as you would learn them in any tutorial, the second however shows the same thing done but with no elif statments. It does the same thing but reduces the code and makes it more debugable in the future.