Class 1: Hello

My Philosophy, your experience

I believe in pomodoros. This class happens to be exactly 3 pomodoros. Let's use 1 to talk about the overview of the course, and set our expectations.

Quick intro: "Language"

Computers are dumb. Sorry. Making them think creatively is hard. BUT they are extrodinary at doing oodles of simple things extremely fast. SO your goal is to convert some interesting problem into something which a computer can do.

Language Hierarchy

A programming language is a compromise between us and the computer. The programming langueg reads a little bit like English, but the commands are structured and the grammar is specific. That way a computer can try its best to make sense of our request.

From This

Our goal is to bridge gap from that (machine code) to this (humans operating the machine):

Hello Computer

Powering up Python

In the lab yesterday you learned how to access Python3 in several different ways. So go to cloud9 and start up a workspace. Find the bash tab (call this the terminal) and type ipython3.

iPython is yet another flavor of python which has some great features for a learning student.

Mini-Task 1:

So what did you learn? Well, a few things:

  1. We saved a value ("Andy is sooo cool.") into a variable (mystring).
  2. We found one way to learn about the methods available to us (think of a method as a function or action or operation being performed).
  3. We used something called tab completion to save keystrokes.
  4. We learned one way to read documentation (we'll see 2-3 other ways to self-instruct).
  5. We performed an action (AKA ran a method on an object).

What I hope you take from this task: the ability to explore what might be possible. When you get home tonight try to learn a new method with this trick.

SYNTAX LESSON: a single equals sign (=) is called the assignment operator. When the program executes a command like: variable = expression it will FIRST try to evaluate/execute the expression (the right hand side) and then SAVE that value into the variable.

Mini-Task 2: store the number 23 into a variable named numBananas

Mini-Task 3: print the value to the screen with the command print(numBananas)

Mini-Task 4: Pick the coolest sounding method that can be executed on numBananas my doing the tab completion trick from above.

Mastering this new idea

In order to cement our understanding of assignment and variables let's look at a ton of examples. First, be aware that we can do plain old math in python.

Try to evaluate the following math expressions using Python:

Mini-Task 5: What do you think are the variables in the following sequence of commands? What is the value of each variable after all is said and done? Run these lines in Python and print the results to confirm.

Questions?

Mini-Task 6: What is the value of x at the end of the following two lines?:

In this case we have assigned a value to x twice! "variables" must "vary", know what I'm saying?

Mini-Task 7: CHALLENGE: What is the value of x at the end of the following two lines?:

So remember that the assignment operator evaluates the right hand side first. So after line 1 we have x equal to 10. After line 2 we have x equal to 10 + 3.

Mini-Task 8: CHALLENGE: What is the value of x at the end of the following three lines?:

Self-Instruction part 2

LIFE HACK: Things make more sense when you have a goal. This is because you can imagine yourself at the end of your project and walk backwards. This will help you see where an idea fits.

So let's give you a goal: Generate a random number from 1 to 6 (roll a die).

You currently don't have any idea how to do this.

Our earlier trick of hitting tab (in iPython) won't work because you don't really know where to start.

USE GOOGLE!

Mini-Task 9: Google search a way to generate a random number from 1-6. Then do it. Then reflect on the steps. (You will find that stackoverflow usually has the most useful code snippets.)

Four other ways to get help

1 help(what_you_care_about_here). Even in regular python you can call help(something) to see some helpful info. Try this with help(list).

2 print(your_thing_here.__doc__). This is a weird one, but you might want it someday. Try the following two lines:

3 The OFFICIAL PYTHON DOCUMENTATION! They have tutorials, offical references, examples, FAQs, install guides, HOWTOs for specific topics, and navigable indices. Good stuff there.

4 Our book (or other books). It has a detailed index, elaborate examples, practice exercises, and is made for beginners.

Mini-Task Z: save the string "I am Zorg, ruler of planet Fun-Fun." into a variable. Use a method to make the string all lowercase. Print it to the screen. Then make the string all uppercase. Print it to the screen.

THE DAILY CHALLENGE:

On Monday when you come in to class I will give you a TOKEN and you will email in:

  1. A new cool Python skill which you taught yourself using any of the methods I showed you today.
  2. A personal goal that you think would be cool to learn to make. (Think: Hangman or Tic-Tac-Toe or A program that emails your a compliment once a day.)
Optional if we have time:

If I haven't timed this correctly then we can continue by exploring %, //, /, len, type, abs, max, etc.