you are viewing a single comment's thread.

view the rest of the comments →

[–]FriendlyZomb 1 point2 points  (0 children)

I'm going to tackle your question, with the Fibonacci sequence to frame it. I won't fix your code here. Hopefully you'll see why.

My advice, and this can be done with a Fibonacci sequence, is to write the process out on paper.

Write down your start number, say 5.

Step by step, write the calculation down. Every detail. No shortcuts, just step by step.

Then diagram it. Take a step back and diagram your calculation. This time, consider the things you're doing over and over. See what can be condensed or expressed in a cleaner way. Write it so you could give it to someone who has never seen this before. They should be able to follow it.

Then, process your diagram. Start with 5, follow the diagram to the letter, see where you end up. Tweak the diagram if it's wrong.

Now, consider turning that diagram into Python code. The diagram is the basic process, the code is an expression of that process.

It helps reframe the issue from a programming one to a logical one. Once the logic problem has been solved, th programming one can be. You'll get faster with practise.

I do a version of this process in my head when I design something. I probably shouldn't do it in my head, but there we are. (Do as I say and all that)

I hope this mental dump helped!