Self mis-taught developer wants to learn the right ways


#1

I decided to embark on a project to build a system some 6 months ago and have been learning python as I coded each line. I’m sure I made a lot of mistakes. Many many years ago I enjoyed programming in Pascal and C, but have not written any code for about 20 years or more.

I hope to fix my self-mis-taught python skills with this course.


#2

Mis-taught skills are normally the best :slight_smile: A good way to improve your python is to write a small piece of code and then ask someone how it could be done differently.


#3

That’s why I am here as well! I’ve been trying to teach myself Python through various online courses to no avail as of yet. I’m hoping that all this coding “stuff” will finally stick. I really want to code! :smiley:


#4

Nice! I know the feeling. I can usually grasp the programming ideas, especially the beginning ideas and I can use those to do whatever. But, I usually lose it when it comes to applying the better way of doing things. Using Python packages (I think they are called packages for Python, correct me if I am wrong) to do something in a few lines that would take many lines for me to do with my own code is something I need to learn to use.
I know doing it the long way can be a good way of learning, but when it comes to the real world, you need to get things done the quickest way, while still being accurate.


#5

Following up on @dirk’s suggestion, here is a solution to MIT 6.189 Homework 1 Exercise OPT.2, posted in order to stimulate discussion on other ways it could be done. One good way for us to learn would be to for us to share samples of code that we can each try out, discuss, and refine.

# SecretMessages.py
# MIT 6.189 Homework 1 Exercise OPT.2
phrase = raw_input("Enter sentence to encrypt: ")
# Ask for shift value; convert user input string to int
shift = int(raw_input("Enter shift value: "))
# Start with an empty string for the encoded phrase
encoded_phrase = ""
asc_a = ord("a")
asc_A = ord("A")
# Loop through each character in the phrase; use c to represent it
for c in phrase:
    # Get the ascii code for the character
    asc = ord(c)
    if asc_a <= asc <= asc_a + 25:
        # c is a lowercase letter; encode it.
        asc_enc = asc_a + (asc - asc_a + shift) % 26
    elif asc_A <= asc <= asc_A + 25:
        # c is an uppercase letter; encode it.
        asc_enc = asc_A + (asc - asc_A + shift) % 26
    else:
        # c is not a letter; do not encode it.
        asc_enc = asc
    # Add the character to the encoded phrase.
    encoded_phrase = encoded_phrase + chr(asc_enc)

print "The encoded phrase is: " + encoded_phrase

So, feel free to copy it, paste it into IDLE, run it, and then throw darts at it here, in order to get the discussion going … :wink: