Q:

How to avoid plagiarism if I am learning from other's code?

I am taking a class that gave us a broad assignment: apply effect to a series of pictures via python. It did not include any lectures on the underlying principles of effects as it would be too broad to cover all.
I am trying to apply focus stacking, but as I didn't know the underlying principles of it (always done it in photoshop). I have looked up the technique of how it is done and landed on a GitHub repo that demonstrated how to do it. I followed along the code and learned the steps of doing it. But in result my code looks very similar to what I just learned. 
I didn't copy and paste any of the code, but I did follow along the steps, I would assume this is still plagiarism? Do I just need to pick a new subject and don't look at any code during the learning process?

A:

You could add a (conspicuous) comment to the code explaining how you wrote the code and that you used the tutorial from GitHub. If you credit your sources and explain how the code come about, it can never be plagiarism.
You could also ask your lecturers in advance whether they think what you did is acceptable. When it comes to programming assignments, there is some variance from lecturer to lecturer in what they consider acceptable.

