Learning to code can be frustrating. There’s a reason they’re called programming languages and when you and the computer can’t understand one another, it’s no different than having to communicate with another person when neither of you share a common tongue; in fact it’s probably worse. This also applies to the flurry of new terminology you have to pick up in order to grasp some of the problems.
It does get easier with time, but it’s the start when you have no basis and there’s no clear goal to even work towards that it’s easiest to get discouraged. If you can stick with it you’ll end up looking back at this and wondering how it ever even gave you pause. So keep at it eh.
In the way this is written we are looking to create a function called to print_list that takes one argument (x). In Python that would be written in the following way-
The next line asks us to work inside this function and use the function itself to print a list one-by-one.
In Python indentation defines the grouping of statements and for code to be considered inside the function (will only run when this function is called) it must be indented following the definition of the function.
A quick example would be the following function that takes a number, multiplies it by 2 and then prints the number.
number = number * 2
For this function named
print_times_two the lines ‘
number = number * 2’ and ‘
print number’ are inside the function. They will only ever be run when the function itself is called.
Since we are provided with code that prints out every item in a list one by one the requirement of this lesson is to move these lines inside the function. This means they have to follow immediately after the function is defined and they must be indented to match the same code block.
Note that indentation is also required in the for loop to group statements together to ensure only certain lines are repeated by this loop.
for i in range(0, len(x)):
It will take some getting used to but this kind of grouping will become clearer with more practice. Good luck.