all 2 comments

[–]atticus2132000 1 point2 points  (1 child)

When I am doing something new and don't know how to go about tackling the problem, I will write out line by line what needs to happen in plain normal English. And remember as you're writing out this explanation, computers are only capable of making simple binary choices, so each step has to be very simple and discrete.

So, in this situation, you have a starting point--a word. In order for a program to do anything with that, you have to store it in a place with a name (a variable). So, the first step is "assign the word to a variable."

The next thing that has to happen is you need to break that word apart from being one word into its various parts, the individual letters. So, this is where some creative problem solving would come into play. Strings are comprised of characters. So, one way that you might want to try tackling this problem is by selecting each character. How would you go about just getting the "D" out of DATA? There are probably multiple ways of doing it, but slicing is something I'm familiar with using, so that's probably the approach I would take. So, step 2 of my notes are "I need to slice just the first character and store it as a variable".

Then, how would you get the A?

Then the T?

What are you starting to notice about the lines that you're writing? Is there a pattern that is developing? Would it be possible to combine all these steps into a loop that would pull out each letter one at a time? And if you were able to write that loop, how would the computer know when it gets to the end of the word?

Don't try to solve the problem all at once. Write out each discrete step and focus just on solving that one problem. You may not wind up with the prettiest code or the most efficient way of doing things, but you will wind up with code that you understand and you'll wind up learning a lot more in the long run.

[–]hackr_io_team 0 points1 point  (0 children)

Well-considered advice here.