What is the best way to learn to code?

In addition to reading code written by others, you also want to modify code written by others. Take one of those programs and ask, what if I wanted a different value of this parameter? What if I wanted to add this feature? What if I wanted to remove this other feature? And see what you have to do to make it happen.

You would be surprised at the number of supposedly college education people who could’t code their way out of a wet paper bag.

But honestly, when I hear that so-and-so has a cert, I usually think of something like Cisco Certified Entry Network Technician or Certified Secure Software Lifecycle Professional. University Diplomas, I feel, are usually in a separate category from certificates, and I believe most interviews and recruiters would agree with the distinction. Certificates in general are highly specialized knowledge and generally take much less time to earn than a college degree; they’re cheaper too.

That being said. Oh my god I’ve interview some terrible college educated candidates.

“Would you please implement a Hash Table?”
“I don’t know what that is.”
“You should have learned about it in your Data Structures class. It’s very common”
“Data Structures was optional at my university” [Either a blatant lie, or a horrible uni]
“Well, thank you for your time. We’ll be in touch.”

“I would like you to implement a binary search on an array. You can use a loop or recursion.”

  • Writes a bubblesort *
  • Uses ‘=’ in place of ‘==’ *
  • Doesn’t even correctly implement the termination condition *
    “Well, thank you for your time. We’ll be in touch.”

Bingo.

In my case, I had to figure it out if I wanted to still get paid. This was way before the internet. And like Dr. Strangelove, it turned out to be fun. I just took a python course online, and was stunned what it could do with the different libraries and data that was free online.

Thanks for your advice, everyone. Please, keep it coming. To give you a vague idea of where I am at the moment, here’s a program I wrote to simulate the Monty Hall problem. I did this off the top of my head, just using my pre-existing knowledge of lists, if & elif statements, loops and the random function. It took me about an hour. It’s obviously going to be very rough and I’m sure there’s a MUCH easier way to do it, but this is what I came up with:



import random

def monty():
    while True:
        doorlist =[1,2,3]
        ans = random.choice(doorlist)
        guess = int(input("Guess a door (1-3): "))
        if guess == ans:
            doorlist.remove(guess)
            round_two = random.choice(doorlist)
            print("You guessed door {}. I will now open door {}.  As you can see it is empty".format(guess,round_two))
            second_guess = input("Will you switch to the other door? y/n: ")
            if second_guess == "n":
                random_generator = ["Lose","Lose","Win"]
                final_result = random.choice(random_generator)
                if final_result == "Lose":
                    print("Ah, Morty.  You're as dumb as they come.  You should have switched up.")
                elif final_result == "Win":
                    print("YOU WIN!")
            elif second_guess == "y":
                random_generator = ["Win","Win","Lose"]
                final_result = random.choice(random_generator)
                if final_result == "Lose":
                    print("Bad luck. You lost. You should have switched up")
                elif final_result == "Win":
                    print("WUBBALUBBADUBDUB! YOU TOTALLY MADE THE RIGHT DECISION!")
        elif guess != ans:
            doorlist.remove(guess)
            round_two = random.choice(doorlist)
            print("You guessed door {}. I will now open door {}.  As you can see it is empty".format(guess,round_two))
            second_guess = input("Will you switch to the other door? y/n: ")
            if second_guess == "y":
                random_generator = ["Lose","Win","Win"]
                final_result = random.choice(random_generator)
                if final_result == "Lose":
                    print("Sorry kid, you lost. That's BUURP Jerry's genes...made you do that. Fuck it, who cares? Ball fondlers is on.")
                elif final_result == "Win":
                    print("YOU DID IT MORTY!  YOU DID IT!")
            elif second_guess == "n":
                random_generator = ["Win", "Lose", "Lose"]
                final_result = random.choice(random_generator)
                if final_result == "Win":
                    print("HELL YEAH, MORTY! YOU GET TO CHOOSE THE NEXT ADVENTURE! YOU EARNED IT")
                elif final_result == "Lose":
                    print("Sorry, kid.  You should've BUUURP switched up.")
monty()


I checked all the parameters and ran simulations until I went cross-eyed and the program definitely works. I’ve been learning Python for about 4 months now but up til now I’ve been quite casual about it. I’ve not been doing it every day (or even every other day, sometimes) but I’ve decided to invest a lot more time into it. I reckon this is pretty much the limit of what I can do at the moment.

P.S. - Excuse the egregious Rick & Morty references. Python can be pretty dry. You’ve got to get your laughs where you can :slight_smile:

If memory serves, the term for this is Functional Decomposition.

I am completely ignorant of Python - I learned back in the days of Pascal and COBOL and haven’t coded in 2 decades - but two issues immediately cry out: you’re not performing any sort of validation on the user’s guess, and you’re directly modifying the array doorlist. For the former, you need to implement some checking, and for the latter you should copy the array and operate on the copy.

That may be accurate from a certain abstract vantage, but (at least where I am) the every day usage of the terms would differentiate between a certificate and a degree. A CS degree will mean that you’ve gotten a general, complete education in the computer sciences over the course of several years. A certificate means that you’ve memorized the specific answers to a specific test, once, for 30 minutes.

You may be beyond this by now, but I found this book extremely helpful. I tried learning through a website, but I felt that the book was much more comprehensive. It also provides exercises to try on your own.

You should check if there is a Python Meetup group in your area. A friend of mine goes to one where programmers basically volunteer their time to help beginners.

I’m seeing a few things in your code that indicate you are new to this. I’m not sure you understand the Monty Hall problem either, or maybe just not how to simulate it. To start with you’re using an elseif when only an else is necessary, either guess == ans or it doesn’t. Also look at your use of variables set to literal values. Do you need to set those variables each time to the same value? Do you need to do the same thing multiple places in the code?

I just glanced at your Monty Hall code. To be frank it is a bit of a mess, which is not at all unusual when first starting out - it is a learning process we all go through. To progress you need to learn to structure your code, make it more modular by separating out different aspects of the problem.

As an exercise I suggest you put aside that code and re-do the Monty Hall problem from scratch, but this time divide it up into several functions. A typical such program might have a function to set up the data structures, a function which processes a single ‘turn’, a further function which accepts user input, and a ‘controller’ function which mediates the interaction between these. Hopefully, with a bit of practice, your code will become clearer and easier to write and understand.

I’m a software engineer. While I’ve learned many programming languages over the years and self-taught, not everyone learns the same. Also, some books, on-line courses and classes aren’t always that good.

The best thing to do, is join a users group in your area. Where you can find mentors to help you not only in-person, but to exchange e-mail with to make comments on your code and answer your questions.

The other things, is learn a new programming language by coming up with a project that is of interest to you. For example, perhaps you want to use Python to access external temperate from different sources such as online services, and maybe a USB connected device, and display this on a web page. From there you are then researching on how to solve your own problem and will leave the language that way. It is best to get the mentors I mentioned involved to help you.

I’m not a good coder, but I do a lot of CAD and I get similar questions about that. As was stated earlier, “practice, practice, practice.”

When someone wants to learn CAD, I usually suggest that they start by doing two things:

  1. Look at a lot of drawings that are part of a design package. Get to know what professional drawings should look like, what conventions are used, and how they solve problems by using different methods to visually demonstrate the desired result.

  2. Pick a project and draw it. I often suggest that they design a deck for a house. Show the types of lumber, accurately dimension it, show details of the hangers and footings, and so forth. Then improve it. You can’t learn to draw from a book. You need to draw.

I’m guessing these principals also apply to to learning to program and code.

Choose something you know for a practice project. You’ve worked in banking and even if you have no interest in it anymore it’s something you know about already and understand well. That allows you to concentrate on translating a familiar process into code instead of working on understanding that process to start with. Breaking down the project into little black boxes has been discussed above, consider some kind of banking transaction and break it down into 5 or fewer steps. Then break each of those steps down into a small number of sub-steps. Repeat until you get it down to little steps that translate easily into code. That’s how you develop an algorithm. You’ll want to simplify your algorithm as much as you can, you’ll look for steps that repeat and when you code you’ll create functions or methods for those to be called from multiple places in the code. When you are ready to code you’re going to do something interesting, instead of working from the top down the way you did to develop the algorithm you will code from the bottom up, starting with the simplest and lowest level steps and then creating the more complex steps that use them. This is called Top Down Design - Bottom Up Implementation. In time you’ll understand it’s value and work out a better concept of the level of steps that you code with.

When I learned HTML 5 and javascript, I set up a project for myself. I put together an interactive web page that converted data entered by seminar participants into credit hours, based on a work project I had at the time. Of course, when I first tried it out, there were errors everywhere, so I googled constantly for correct syntax.

One thing I noticed is that programmers ascribe different meanings to everyday words and you absolutely have to define your terms to the nth degree so they won’t assume you mean something else. This was REALLY frustrating.

Another thing is that programmers assume you already know procedures that are as normal to them as breathing, thus they don’t bother to list them when describing how they coded something. Also extremely frustrating. I put together a blog outlining my frustrations and included all those procedures everybody needs to know, for the sake of novice programmers also struggling with coding. I doubt anybody found it, as I have yet to get any feedback

Eventually I got the project done to my satisfaction and tried to find a PHP server to test it. Again, I encountered the vast gulf of ignorance that is NOT covered by PHP gurus because the typical user is assumed to already have the prep work done. My workplace had no available PHP servers. I tried turning my own computer into a PHP server, only to find that firewalls and such blocked my every turn. Bottom line: you can’t do this by yourself unless you’re really good friends with somebody who works IT.

GOOD LUCK!

My problem is I can’t seem to find how to actually implement python. How do I integrate it into a website or how do I make a video with it like 3blue 1brown does?

Or write a database. If you can code that then you can code any basic project.

Keep it simple and do things on the command line. Once you’ve done that, then figure out how to get off of it.

Ummm… that’s my issue. How do I integrate it into a website or make a youtube video? I can run the script from the command line.

The easiest way to integrate basic Python scripts into a webpage is to use the Common Gateway Interface (cgi) module. This allows you to call Python scripts from the webpage and return parameters or do other simple operations on the webpage. If you want to do more complicated things like 3D animation, scientific data visualization, or heavy interactive interfaces, then you are better off finding a toolkit or framework which already has the necessary functionality and spend your time gluing together elements to do what you want them to do rather than roll your own interface from scratch (although it is useful to understand the elements that go into a framework). But first, master the basics of writing and testing “pythonic” code, and then get fancy. There is nothing worse than poorly hacked code written by someone who is trying to make Python work and look like Fortran or Java.

Stranger

Take a real class where you go to a room with an instructor and other students. Since you’re just starting out, it would be really good if you took an intro to programming class to first learn how to think like a programmer. Or more long term, look into a 2-year program at your community college. Most companies will prefer a Bachelor’s degree but you can open a lot of doors with just an associates degree.

It is possible to learn on your own, but you’ll have more trouble later on if you want to make this your profession. Pretty much no one will hire you unless you can demonstrate a lot of competency. The online courses are great if you just want to program some applications for your own needs, but will likely not be sufficient to get a job as a programmer.

One avenue you might want to pursue is to be a tester or QA person. It will be easier to get hired that way. Even if you got a Bachelor’s degree in computer science, you’d be competing with lots of college new hires and your age would be a disadvantage. But as a tester, you will often have opportunities to program scripts and test suites. This can often lead to programming jobs in other areas of the company.

Keep at learning Python, but consider opportunities other than being a programmer. The chances of a self-taught, 35-year-old programmer getting hired as a software developer are not the best. But having programming knowledge can greatly help get you into other opportunities.