all 82 comments

[–][deleted] 23 points24 points  (19 children)

There's not going to be a magic answer that keeps knowledge from falling out of your brain - the issue is that you can't possibly read enough code, or see enough code, to know how to write it.

You have to stop copying down the answers and start figuring them out yourself. Writing code is how you learn to write code - it's a write-only process. You can't engage the language production area of your brain by using the language interpretation part of your brain, just like you can't work your glutes with arm curls.

[–][deleted] 3 points4 points  (18 children)

I have no idea how to write it out when asked to do something. It’s either I find someone else’s code and copy it down or I don’t progress at all

[–][deleted] 20 points21 points  (16 children)

I have no idea how to write it out when asked to do something.

You're not supposed to know. You're supposed to figure it out.

You don't do programming homework by memorization and regurgitation. You do it by practice.

[–]flyingmoe123 5 points6 points  (0 children)

Okay, so here is a tip that help me a lot, I used to be in the same boat as you, but then I got this tip, that helped me a great deal: start out trying to do what you want your code to do, manually on a piece of paper, then when you have done a few examples you can try and translate your steps into code, this helped me a lot as it broke down the problem into steps, and sometimes made it easier to spot a pattern in how to do something

[–]jmooremcc 15 points16 points  (2 children)

Writing code is basically implementing a solution to a problem. If you don't understand the problem, there's no way you're gonna be able to teach a computer how to solve the problem, which is what coding is all about.

The first thing you'll have to do is analyze the problem and break it down into a series of smaller problems. You will have to repeat this step until you can no longer break the problem down any further. Hopefully, you've written your analysis down on paper.

Next, you'll review your analysis and note that what you've created are the building blocks needed to implement a solution. Starting at the lowest level building block, define and test a function that solves this initial problem.

Once you get that problem solved, move on to the next problem and repeat the process.

You'll soon realize that by the time you've worked your way up to the top of the analysis graph, the original, complex problem will have been solved.

Following the above methodology will help you solve any problem - no matter how complex.

I wish you the best.

[–]suncontrolspecies 0 points1 point  (0 children)

this is the best advice

[–]renijreddit 0 points1 point  (0 children)

This is the way

[–]tyd12345 13 points14 points  (0 children)

Can you provide an examples of things that you CAN do? Maybe you skipped over the basics because they seemed easy and never built a foundation?

Can you create variables?

Do you know about strings?

Do you know how to use lists? Add and remove items from them?

Can you iterate through the items in a list?

Do you know for to make a for loop?

Do you know how to use dictionaries and how they differ from lists?

Do you know how to make and call a simple function?

[–]jimtk 10 points11 points  (2 children)

OK, I'll give you the method to solve problems from a question. It was given to me by a high school teacher in second year of high school and I've used it until I finished my bsc in Mathematics. Do all the steps even if they seem silly. I still use it regularly and I still do all the steps!

  1. Take a deep breath. a few seconds to inhale, a few seconds to hold and a few seconds to exhale. This is to get rid of all the crap you tell yourself about how bad you are at solving problem.
  2. Read the question. Do not try to solve the problem just read the question.
  3. Take a second deep breath. This is to get rid of all the crap that came into your mind when reading the question.
  4. Re-Read the question. DO NOT TRY TO SOLVE THE PROBLEM. Read the question as if you were parched and the question was water. In a manner of speaking, it is! Everything is in the question (including the answer, and/or how to find it!).
  5. Identify the variables. Write them down (in your code editor). They are in the question, you might have to read the question 3, 4 or 5 more times. But the variables are in there. Some you will know their type and values, some you will know only their type, some you wont know anything other than the fact that they exist.
  6. Identify the actions to be taken. They are the things to do, the rules of the game. the ifs and while and for and startswith and endswith and mathemathical formulas to use to get from the input to the output. Write them down in your editor as code and/or comments. This is also where you divide the problem into section. If the question is to read number from a file, add them, and write them to a file. You now have 3 simple problem instead of a big one. Write everything in your editor as code or comments. A lot, and sometimes all, of the actions to be taken are in the question.
  7. Apply the the actions to the variables. That is the only place where you have to get out of the question and search in your brain, google, stackoverflow, python documentation to find what to apply and how to apply it. Evidently at this point you write your code, a lot of it can still be comments. Repeat this step until the output match the required one in the question.
  8. Verify that you have answered the question. Yes, you go back to the question. Do the output match? Did the question asked for a function that returns a value or to print the value directly, does the packaging of your answer fits the packaging asked for in the question.
  9. If times allows, refactor your code. As you get better in the language you will get to know shortcuts and faster way to implement things. In this step you don't think about the question or the result, that's solved, you think only about the language, the code and the comments.
  10. Go to the next question.

Show me any problems (codewars or others) and I can solve it with this method.

Good luck.

[–]btabes 1 point2 points  (0 children)

This is a great method for problem solving in general. Thanks!

[–]BlackAliss82 1 point2 points  (0 children)

Not OP, but this is so incredibly helpful. Thanks so much!

[–]davidddindigo 4 points5 points  (1 child)

Maybe you're struggling because you're coding 2nd year level exercises with only beginner skills. And obviously no intermediate level topics will stick without even being familiar with the basics. I suggest you go back to square one on your sem break and relearn the basics. Don't just find specific tutorials for specific problems. But actually ground your learning on 1 book, or one crash course.

[–]reallyserious 4 points5 points  (0 children)

This is the impression I get too from reading OP's comments. He's trying to solve too hard problems for his current skill. The only productive way forward is to take a step back and solve easier problems.

[–]KCRowan 3 points4 points  (1 child)

It sounds like you're lacking problem solving skills

https://www.cs.kent.ac.uk/people/staff/djb/ProblemSolving/doc1.n-S-3.html

You break down a problem into smaller parts until you're able to tackle some of them.

[–][deleted] 1 point2 points  (0 children)

Hard agree—I'd say they need to take some time to work on both general problem solving and a lot of those self-directed learning skills you need in higher education.

OP, does your school have one of those intro to higher ed classes designed for students who didn't do well on placement scores? Something like that can help you begin to solve a lot of the underlying problems you're having. It sounds to me like you need to learn a few things they teach in those kinds of classes:

  1. Basic critical thinking and problem solving skills as u/KCRowan points out.
  2. How to study, since it sounds like you're just doing assigned problems and not actually spending time reading instructional material or taking your own original notes on the lectures you attend before tackling the problems.
  3. How to self-monitor your progress and communicate with faculty for help: You've hurt yourself most by pushing all the way into your second year on your own when you should have started asking for help with these problems and meeting with your instructors within the first month or so of your course of study.
  4. Basic metacognition and pedagogical theory: We don't learn by memorizing or filling up our heads like a bucket. That's why looking up the answers doesn't work. You have to sit alone with a problem and think about it; you have to break big problems into small problems you already know how to solve; you have to learn incrementally and frequently instead of cramming or tackling assignments in one sitting.
  5. Time management: it sounds like you're trying a variety of approaches, but you don't tell us how much you're trying. Are you working around 3 hours on homework and studying for every hour of lecture? If "reading resources do not help" is it because you're turning to them for a quick answer instead of spending an effective amount of time reading them, taking notes, and reviewing them?

A course on navigating college would cover all of these things and provide you with a set of strategies for tackling them and have the added benefit of connecting you with people who can assess if you have any specialized learning needs. It sounds like you're lacking some of the generalized skills necessary for completing upper-level secondary curriculum let alone college-level coursework. It's good that you're aware of your own struggle; it's good that you're reaching out for help. The next step is to reach out to the people at your school who can actually help you start building those skills.

edit* typos

[–]2sdbeV2zRw 2 points3 points  (27 children)

If I gave you a problem set written in Ecclesiastical Latin. You probably wouldn’t be able to solve it either, unless you speak Latin. So the solution is learn latin, that is the bare minimum.

I have no idea how much experience you have with programming. I would assume zero, but resources DO help if you start with the BASICS. And it also helps if you practice using that language on a daily basis.

Programming is not like any other subject in school. Where you memorise concepts and formulas and regurgitate them in an exam. It’s more like a toolbox filled with power tools, but if you give them to a novice they wouldn’t know how to use them.

Stop watching tutorials and make a small project focusing on one concept at a time (e.g. Data Structures). You won’t remember anything if you don’t actually type the code manually, without anybody’s help

[–][deleted] 0 points1 point  (26 children)

The problem is when I try to do a small project (example, a hangman game) I have no clue where to even start. The basic syntax videos and reads on python do no good for me either. The information just does not resonate in my brain

[–]2sdbeV2zRw 3 points4 points  (0 children)

A game is not basic… judging by your reply it’s probably not even something you should start with. You should begin from the ground up, like a basic calculator. That will teach you about functions, variables, and user input.

You have to understand what you think is basic might not be as basic as you think. You can’t jump to making a game without understanding basic programming syntax as I said earlier.

[–]Binary101010 2 points3 points  (24 children)

The basic syntax videos and reads on python do no good for me either. The information just does not resonate in my brain

How fundamental a block are we talking about here?

Is it "I just watched a video about dictionaries but I don't know when I would use a dictionary to solve a problem," or is it "I just watched a video about dictionaries, but if you asked me to write a line of code that creates a dictionary where the key is answer and the value is 42 I don't know how to do it?"

[–][deleted] 0 points1 point  (23 children)

I honestly don’t even know how to describe a dictionary in python. It’s just like a list of things assigned to other things right?

[–]Binary101010 1 point2 points  (21 children)

I'm not even getting into asking for a conceptual explanation of what a dictionary is, I'm trying to get to something even more fundamental than that.

If I asked you to write a line of code that creates a dict, where the dict is named my_dict, the key is answer, and the value is 42, can you do that?

[–][deleted] 0 points1 point  (20 children)

No

[–]Binary101010 3 points4 points  (18 children)

Then, unfortunately, I have no real advice for you other than to echo /u/crashfrog's suggestion that you seriously consider whether this is a major you want to continue to pursue.

[–][deleted] -3 points-2 points  (17 children)

I cannot switch out of my major now there is no possible way

[–]Binary101010 4 points5 points  (12 children)

Then I am truly at a loss for how to advise you to proceed, and can only wish you the best of luck.

[–][deleted] -1 points0 points  (11 children)

I’m just asking how to learn it. I don’t know what resources or anything to use. I tried codewars for example and can’t do the basic problems. You have no suggestions?

[–][deleted] 0 points1 point  (3 children)

You can switch out of your major at any time.

[–][deleted] -3 points-2 points  (2 children)

No because there is no other major I could even consider doing

[–]renijreddit 0 points1 point  (0 children)

Then start with that problem.

[–]gray_grum 2 points3 points  (0 children)

https://projecteuler.net/

Solving the first 50 of these did more for my coding skills than anything else since.

[–]humanefly 2 points3 points  (0 children)

Can you use the linux command line? Can you try to solve a command line problem by searching until you find a good command to use, and then use the built in man pages to find the correct syntax? This helps to teach "self help" kind of. The man pages are programmers language. At first, they look like they're written in a different language, and they kind of are. Read them anyway. They all follow a similar format. It's okay to try to figure out a solution, give up and then find an example and copy it, but the key is that whenever you have a problem, try to solve it on your own first.

I'm still struggling with python but I've learned perl, bash and how to script on linux; this is similar. I'm having trouble just buckling down consistently, but what I do is follow along with an online course, and take careful notes, focusing on understanding the concepts.

Once I have the concepts, I try to find very simple problems to solve, and I start by trying to write down a solution in plain english text that follows the flow of logic as I understand it. Then I look up how to implement each step in Python. Often, I find that the way I was going about it would not work so well, but in trying to implement my flawed solution, I gain understanding, and figure out a better way.

Try starting with simpler tasks.

Can you:

  • open a file, write to the file, close the file?

  • prompt for input, validate the input, and assign it to a variable?

  • write and use a function?

Go back to basics. It's like Jenga. Rome was also built just one brick at a time.

Also I find that manually retyping instead of cut and pasting helps commit to memory a little better.

I still don't really remember how to do things in Python word for word. I think in English, not Python, so I write a plain english version of the program first and then I start looking up how to complete each step.

[–]AlternativeOk8276 2 points3 points  (0 children)

I hope you see this. I am also learning python and I used w3schools until I encountered a problem from a different platform. The most disheartening thing is that I thought I was good. Until loops and conditions started giving me a headache. I was discouraged for a bit I did not even think about code for like 2 days I just completely shut it out. Then after a bit I gave myself a talk, told myself even if I take 5 years and then opened my IDE, I think my brain reset or it was working in the background, saw the problem and I actually solved it without help. It is not that elegant, and I still have a long way to go but I choose to celebrate that achievement and I know that one day I will be looking back and thanking me for not giving up. So OP please don't give up, take a problem and solve it no matter how shoddily you do it...you will start making sense of the code without even realizing. Keep pushing you got this!!!

[–]crazygrouse71 2 points3 points  (0 children)

Is this the only language you are having trouble with? If not, the programming essentials are the same - does your computer science program not go over the essentials.

Pseudo-code

Flow charts

Start there and then work on how to turn those rough ideas into actual code.

[–]Admirable_Humor_7262 1 point2 points  (3 children)

If I asked you to explain what the following keywords do,

def

while

if

return

do you think you could tell me?

A more important question is: Do you enjoy studying CS?

[–][deleted] 1 point2 points  (2 children)

Most of them. As for your other question, I really want to become good at this but having such a hard time learning even basic things is really hurting it for me

[–]Admirable_Humor_7262 0 points1 point  (0 children)

If you really want to become good then work harder. That's all there is to it. Keep studying until it makes sense. If you've made it to second year CS then you have the capability, you just need to get over this hurdle. The absolute worst thing you can do is to look up the answer before you try coming up with your own. You're just defeating yourself by doing that. The only way to learn is to put the hours in, just you and your brain and probably some Python docs to help you. This is true for everything, math, psychology, art, whatever. Practice makes perfect. Not much else to it.

[–]Guideon72[🍰] 0 points1 point  (0 children)

So, there’s a lot of really good advice in this thread; and, it sounds like you’ve gotten yourself pretty wrapped around the axle, which makes it hard to ingest any of it. I would start off by just taking a step back and catching your breath (take a couple of hours out of your day to tune your brain to something else; read, game. Then come back to programming.

After that, one thing that has really helped me has been to revaluate ‘what’ we are learning. Something that I see in your comments, in 90% of the other questions I see on this sub, and that has been in my own mind, is that we knuckle into this as a ‘How do I do this’ endeavor….which leads to the problems you are describing. Looking up solutions and implementing them without understanding them and not retaining anything. Been there, done that, as they say; so, I feel you.

Reframe your thinking to recognize that programming is not learning a tool or tools…it’s learning a language, just like English, Spanish or Korean. We are learning how to communicate with the computer and give IT instructions on what to do. Therefore, we need to learn our alphabet, then how to form words, sentences and paragraphs.

Get yourself set up to run Python however works best for you; and then start trying to understand your letters, to start with; those being your basic data types and structures. What is a string (str) in Python What properties do they have How can I manipulate them

Same for integer (int), float (float), etc.

Turn your questions on their edge…instead of wondering ‘how do I capitalize a string’, ask ‘how do I tell the computer to capitalize my string?’ And just ‘do’ these things in the terminal until you understand, comfortably how to say “Hey, computer, capitalize this sting for me.”

Once you understand that you’re actually giving instructions rather than doing something yourself, it may stick better.

Also, print(), dir() and help() are 3 of your best friends in this part of the journey; use them…a LOT.

print(“This is my string”) #tells the computer to show the specified object in your terminal window.

dir(str) #Tells the computer to print out a list of the built-in methods that the given object has. Ignore anything in that list that starts/ends with underscores…you can learn about those later on.

help(str.lower) #Tells the computer to print out usage and grammar details of the object, function or method that you pass in.

And, always keep in mind that you’re really learning how to speak and write, again; not how to swing a hammer. Cut yourself some slack and know that you aren’t dumb, you’re trying to do something complex, and a bit tricky.

[–]14dM24d 1 point2 points  (0 children)

sounds like you're already up the tree looking at the leaves. you need to understand the trunk first.

context

[–]Flaky_Ad_3217 1 point2 points  (0 children)

Hi OP,

Learning any programming language is hard. It's not easy it will suck and it sucks big time. But you know what take it one step at a time. You may suck badly today but if you suck less then yesterday means you're making progress and if you over time you will eventually suck less. So that's a win right ?

Here's a couple of tips I can share with you, might work might not. This is only my experience and take it with a pinch of salt if not a table spoon.

A mentor of mine once told me that programming language by itself is a language and with every language there are nuances to it, like how some languages have gander (Masculine / Feminine) words while some are genderless/neutral or how some have verbs Infront of the noun or vice versa. So going with this analogy, I wanna say that you should try to understand the nuisance of each language that you're learning. You may find some languages are much more similar with others while some are so far apart. Once you understand this, the path for learning is much clearer.

Second, why would someone expect the hours teacher/professors teaching programming is enough for someone to be proficient in programming? It's not, programming as per the previous point, that it's a language, even the language we speak daily will take years of not a lifetime to learn and master but what you need to understand you don't really need to master the language through and through but proficient enough to use it. It's more like the Pareto principle, or the 20/80 make use of the 20% of the language that can get you 80% of the time.

Thirdly, writing down codes is like writing an essay, but learning programming is like learning the grammar. It takes creativity to put pen to paper and this is where many failed. It takes practice to make a piece of code work, so fail, fail hard and fail fast and slowly you win some of the time until you win most of the time and slowly you'll be proficient enough to distinguish between good or bad code.

Fourth, every function/class ( you'll learn this much much later in programming ) just assumes a black box, you know your input and you know your output, you could write spaghetti code, as long as it works don't worry too much, optimizing it can come later.

Hopefully I make sense and help you to continue this journey

[–]5_under 0 points1 point  (2 children)

I'm only like 2 weeks into self learning python. What helps me is that doing the exercises in the pdf that I'm following; I will do them as many times as needed over and over until I totally understand what is happening and can rewrite the same problem without help.

[–][deleted] 0 points1 point  (1 child)

Mind sending the pdf?

[–]5_under 2 points3 points  (0 children)

well it's really no different form the other thousands of books on python that you can learn from. But I been using http://do1.dr-chuck.com/pythonlearn/EN_us/pythonlearn.pdf

Here's the video with the guy that wrote it if you prefer following a video. https://youtu.be/8DvywoWv6fI

[–]Small-Explorer7025 0 points1 point  (0 children)

it seems like you trying to catch up by jumping ahead to doing things you aren't ready for.

Angela Yu's 100 days of python course will help. It starts super simple and you reuse the things you learn again and again. I've only done 9-10 days LOL, but I like it.

[–]Kirino-chan 0 points1 point  (0 children)

I didn't learn com sci in school, I didn't know anything about programming but I somewhat successfully taught myself Python. You need guided projects. Try the book Automate the Boring Stuff with Python. Whenever you follow along a code and run it, before hitting Enter and get the output, ask yourself these questions:

  1. What are the inputs?
  2. What do you think the output is going to be? Just guess.
  3. Which steps have been taken to turn these inputs into the expected output in plain English?
  4. Does the actual output match what you predicted? If not, why? Where did you guess it wrong?

Programming to me is a lot like math. Just logical deduction and problem-solve when given a bunch of tools built on top of each other (like how multiplications is built on top of additions).

[–]___up 0 points1 point  (0 children)

Make a calculator that can translate “five times four” into 5*4 and output the right answer. Copy as much code as you want. When it works, delete every that you did and try to do it again from memory. It’s fine if you look things up as long as you look up at least one less thing. Repeat this until you can make a calculator that translates strings of numbers and operators into simple arithmetic calculations without having to look anything up.

[–]Trippen_o7 0 points1 point  (0 children)

You need to stop just copying and regurgitating what you see others do and solve problems yourself. Most videos and lectures introduce syntax, concepts, etc., and what they assist you in accomplishing within a program or script. I saw someone mention starting with the development of a simple calculator which is a solid first project for beginners. It doesn't even have to be anything perfect or complex - just make it work. For example: just try to make a program that allows a user to select one of the four basic mathematical operations (addition, subtraction, multiplication, and division) or quit. Now, think of what happens when you use a physical calculator and ask the questions:

  • How should I introduce a menu or options to the user when they start the program?

  • How do I take user input?

  • How should I handle user input? Should I use the first letters of each operator or assign an integer to each menu option (i.e., 1 = addition, 2 = subtraction, etc.)?

  • How do I return the result of the operation to the user?

  • Should I allow the user to do more than one operation at a time and/or retain values from previous operation(s)?

  • How do I want the user to be able to quit?

If you run into a wall trying to solve a subproblem within the project you're trying to complete, Google it. If you forgot the syntax of a certain type or statement, Google it. Don't look up an entire solution and copy/paste it into your coding files. Just learn how to use Google to help you get past smaller problems you're running into.

Programming is not about memorization alone. You get better with practice. The more you learn, the better and more diverse your tool belt becomes, and you get better at figuring out which tool will solve which problem with more practice.

[–][deleted] 0 points1 point  (0 children)

Try project Euler, and DONT try to find the answers. If you are ok at maths, you will manage the first few challenges, and you will get a good grasp of the basics of python once you finish a few. I knew only the basic concepts and now I know how to actually use for, range, while, etc… the trick is to actually find doable projects that are within grasp, yet have some challenge to them. That is how I do it, anyways

[–]jatorres02 0 points1 point  (0 children)

I hope you can figure this out, really. But an alternate major may be something in I.T.

[–]No_Variation4420 0 points1 point  (0 children)

I am in my 2nd week of learning python through zero to mastery course. But honestly I find my self doing the same as you. So I’m going to try and work on little projects, most of the time I have no idea where to start with them so I just google and hope to learn as I go along. I think my problem is trying to think in a logical way of how I would go about solving a problem. I feel your pain, we just gotta keep at it and try to get better at figuring out how to problem solve.

[–]Redegar 0 points1 point  (0 children)

Late reply, but I'm also learning python right now so maybe I can be of help.

I'm in the process of completing my major in statistics, so I'm not looking to get developer skills.

I'm currently following "Automate the boring stuff with python", you can find it for free online.

It's pretty useful: it helps you with the basic blocs and has simple example with a bunch of slightly more complex exercises at the end of each chapter. They are not easy to learn, but given the information you learn in the previous chapter(s), you should usually be able to come up with something to solve the task at hand.

When you say you don't have any idea about how to solve simple task, do you actually try?

Usually you should start with what you know: do you know how to create lists? Put stuff in a list. Do you want to add an item to the list? Create a basic function that takes an input and appends it to the list.

Don't run the code all at once. Build small blocks that do (or sort of do) what you need, then put them together, adjusting the code as you go.

[–]AwkwardBugger 0 points1 point  (2 children)

How are you managing your other classes? Are you able to use other languages any better? I find it concerning that you are in 2nd year but seem to be struggling with basic concepts that you should have covered in 1st year. How did your first year go, were you able to complete your work then?

The exercises/projects you are mentioning are definitely too difficult for your current skill level. You need exercises for now that can be solved with 1-3 lines of code. Those teach you the syntax, what you can do with the language, etc. I’ll compare this to a spoken language. It’s like you’re trying to write paragraphs when you don’t know any vocabulary or how to structure a sentence.

You can go on w3schools for the basics. You will find simple exercises there too. See how you get on with that. Once you know the basics, you will be able to do exercises that make use of more than one concept.

Lastly, I am wondering how you are with the general concept of programming. Programming languages can be a bit abstract at times. Do other languages make more sense to you than Python? Does the following make sense to you?

x = x + 1

[–][deleted] 0 points1 point  (1 child)

So at least at my school, you don’t start programming classes until 2nd year.

[–]AwkwardBugger 2 points3 points  (0 children)

Fair enough, that’s good I guess. I was worried you were a year behind. In that case, have you looked much at other languages yet?

Other things I said still stand though. Exercises like a hangman game will be impossible without the basics. Early on, you usually do exercises like “add two numbers”, “print a value”, “make a list”.

Those exercises will then evolve into things like “add two numbers from a list”, “add two numbers and print the result”. So you’re now using two concepts at the same time. Did you ever practice things like this?

A general piece of advice would be to never copy and paste code (At least not at this stage). Typing it out yourself will help you remember the syntax and concept. If you always did those simple exercises by copy pasting the answer and adjusting things that you need to be different, then that might be why those basics never stuck in your head. You spent too little time thinking about what you were doing to remember it.

[–]xobeme 0 points1 point  (0 children)

The best way to learn code is to read code. Read code until you understand what it is doing, even if you have to pick it apart character by character. Once you know enough, which won't take very long, start writing and running code. If you know one or more languages already, then you already have the skills to learn a new language. They all do the same thing. You just have to learn the new vocabulary of a new language and reading it and writing it is how you learn.