• Getting Started With Python Part 2 – Codecademy Beta! – Whitespace and Statements & Comments & Mathematics

    by  • July 7, 2012 • Project Weekend

    Whitespace and Statements

    Now that you’re getting the hang of variables, values, and assignment (think of them like the subjects, objects, and verbs of English sentences), let’s take a look at whitespace and statements: the sentences of our new Python language.

    Ok, so I have got to level 2 here, as you can see, and the column on the left has some wise words for us:

    You can think of a Python statement as being similar to a sentence in English: it’s the smallest unit of the language that makes sense by itself. Just like “I,” “like,” and “Spam” aren’t statements by themselves, but “I like Spam” is, variables and data types aren’t statements in Python, but theyare the building blocks that form them.

    To continue the sentence analogy, it’s clear that we also need a kind of punctuation to make it obvious where one statement ends and another begins. If you’re familiar with JavaScript, you know that statements end with a semicolon (;). In Python, statements are separated bywhitespace. Just like you can’t toss around semicolons wherever you want in JS, you can’t throw whitespace around in Python.

    This may take some getting used to, especially if you’re coming from a programming language where whitespace doesn’t matter.

    Getting Started With Python Part 2 – Codecademy Beta! – Whitespace and Statements - 1

    Getting Started With Python Part 2 – Codecademy Beta! – Whitespace and Statements – 1

    Getting Started With Python Part 2 – Codecademy Beta! – Whitespace and Statements - 2

    Getting Started With Python Part 2 – Codecademy Beta! – Whitespace and Statements – 2

    Getting Started With Python Part 2 – Codecademy Beta! – Whitespace and Statements - 3

    Getting Started With Python Part 2 – Codecademy Beta! – Whitespace and Statements – 3

     

    Comments

    Written by Eric Weinstein

    Single Line Comments

    You may have noticed the instructions in the editor that begin with a # (pound or hash) symbol. These lines of code are calledcomments, and they aren’t read by the interpreter—they don’t affect the code at all. They’re plain English comments written by the programmer to provide instructions or explain how a particular part of the program works.

    Since this improves the readability of your code tremendously (and will help you debug programs more quickly, since you’ll be able to tell at a glance what each part of the program is supposed to do), we encourage you to comment on your code whenever its purpose isn’t immediately obvious.

    We aren’t in Kansas anymore fellas, here we have a bit of a challenge.. just press run!

    Getting Started With Python Part 2 – Codecademy Beta! – Whitespace and Statements - 1

    Getting Started With Python Part 2 – Codecademy Beta! – Whitespace and Statements – 1

    Getting Started With Python Part 2 – Codecademy Beta! – Whitespace and Statements - 2

    Getting Started With Python Part 2 – Codecademy Beta! – Whitespace and Statements – 2

    Math Operations

    Written by Eric Weinstein

    Python’s statements aren’t limited to simple expressions of assignment like spam = 3; they can also comprise a number of mathematical expressions using arithmetic operators.

    There are six arithmetic operators we’re going to focus on:

    1. Addition (+)
    2. Subtraction (-)
    3. Multiplication (*)
    4. Division (/)
    5. Exponentiation (**)
    6. Modulo (%)

     

    Ok here come the screenshots thus far!

    Getting Started With Python Part 2 – Codecademy Beta! - 3

    Getting Started With Python Part 2 – Codecademy Beta! – 3

    Getting Started With Python Part 2 – Codecademy Beta! - 4

    Getting Started With Python Part 2 – Codecademy Beta! – 4

     

    Getting Started With Python Part 2 – Codecademy Beta! - 5

    Getting Started With Python Part 2 – Codecademy Beta! – 5

     

    Getting Started With Python Part 2 – Codecademy Beta! - 6

    Getting Started With Python Part 2 – Codecademy Beta! – 6

     

    Getting Started With Python Part 2 – Codecademy Beta! - 7

    Getting Started With Python Part 2 – Codecademy Beta! – 7

     

    Getting Started With Python Part 2 – Codecademy Beta! - 8

    Getting Started With Python Part 2 – Codecademy Beta! – 8

     

    If you are wondering why I did not put much words into this last part; it seems self explanatory how to do computer math for any high school student level educated person. I wont bore you with the details. Rest assured it took longer to complete the screenshots than it did the whole unit.

    Codecademy Python Beta - All Finished!

    Codecademy Python Beta – All Finished!

    And just like that, I’ve finished! I do not feel, however, like I know Python, so I will most likely be scoping out some Python ebooks when I am done hacking this Nook Color later tonight.

    I hope you guys had a great time following along, and I sure had a great time leading you! If you really like my work, and the things I say, please SHARE LIKE AND SUBSCRIBE RAAAAAAWWWRRR !!!

    About

    James is an active member of his local tech community in Memphis, TN. He is a student of Science at the local college and an Information Security hobbyist, as well as an outspoken Linux Advocate, and open source proponent. After a hard day at the console, James likes to enjoy a vintage 2012 Mountain Dew, with a robe and a pipe by the fire.