You'll get a knack for it eventually, just keep playing about with it and re-doing tasks that you're given until you understand what every line of code is doing. Try commenting on each line, describing what they do, then ask your lecturer or other students about any parts you can't explain.
Like anything in life, you won't get better at it by trying to take shortcuts, just do it over and over and over again. That's how you learn a language, an instrument, how to draw, and it's how you learn to code well.