8.1 Mistake #1: Forgetting Your Closing Parentheses
Consider the block of code:
= int(input("Please enter a number here")
number
print(number)
On first glance, the above code block looks like it might run. However, to the observant eye, it will not. This is because the very first line of the above code block is missing a closing parentheses for the int()
function!
Because of this, Python will return a syntax error if you try to run the code as is. Here, Python assumes that everything that follows after the input()
function’s closing tag is an argument of the int()
function (which is not).
8.1.1 What can I do to avoid this?
If you are using Colab, Spyder, or some other IDE4, a pair of opening and closing parentheses should be generated for you when you begin a new opening parentheses.
Otherwise, Colab, Spyder (not sure about this - perhaps somebody can verify), or the IDE of your choice should also have highlighting features to show you a pair of opening and closing parentheses:
Therefore, if you are missing your closing parentheses, you should be able to pick it up very quickly as both sides of the expression will not be highlighted (or in the case of some IDEs [e.g., RStudio], a message will appear notifying you of your mistake).
IDE = Integrated Development Environment - it’s a piece of software that provides the developer with an interface for code development, testing features, and also debugging features.↩︎