In programming languages, syntax is what makes or breaks code. For a language like Java, this means putting blocks in curly brackets {}, and terminating lines with a semicolon ;. Python is one of the easiest languages to learn because of its forgiving syntax, with the biggest thing to keep in mind being indentation for code blocks.
1: Syntax and Indentation Rules
Python uses indentation to define blocks. Missing colons or inconsistent spaces cause immediate errors.
Contributed by Bijou Raj
In [1]Text cell
In [2]Code cellpyodide
In [3]Text cell
Whenever we get an error regarding indentations, make sure to check that all lines are where they should be in terms of spacing. Try fixing this one!
In [4]Challenge cellpyodide
In [5]Text cell
Since this is just foundations, we won't too in depth on all the different cases where this could be problem, but it helps to keep this rule in mind: if we want it to be executed in the same section, we need to indent in the same section.
In [6]Code cellpyodide
In [7]Code cellpyodide
In [8]Text cell
Try fixing each of these code cells so that they run without any errors!
In [9]Challenge cellpyodide
In [10]Challenge cellpyodide
In [11]Challenge cellpyodide
In [12]Challenge cellpyodide
In [13]Text cell
Indentation is important, so if code isn't working, check for that first!