Day 1: Hello World

Reminder: if you have any difficulty, email me at bmcmahan@njgifted.org with questions! Failing is good. Failing silently is bad.

Summary

Our first lesson!

We made excellent progress through all of the material. In fact, we even got ahead of where I thought we’d be. Not only did we cover the basics of Python’s variables, but we got started on strings! The review for strings will be left on the day 2 page.

When you practice, you should be trying to identify how code can break! Knowing how things break is the best way to make them not break.

Review

Values are data - things like 25, “Hello”, and 3.14159. Variables are just containers that hold that data. Each variable you use in code gets its own name - it’s like an envelope that you label so you remember what’s inside of it. You make variables in Python using the “assignment” operator, which is the equals sign (=). Here are some examples:

x = 5
my_text = "Hello, World!"
num3 = 3333.333
text_number = "500"

(Remember - you can tell if a variable is a String if it’s surrounded by ‘’ or “”)

There are 4 main types of data in Python:

  • Integers (numbers with no decimal place)
  • Floats (numbers with a decimal place)
  • Strings (text, surrounded by quotes)
  • Booleans (True or False)

We learned three commands:

  • print(), which prints out whatever you put in the parentheses
  • type(), which evaluates the type (integer, float, string, boolean) of whatever is in the parentheses
  • len(), which evaluates the length of whatever is in the parentheses. For example, len(“Hello!”) = 6

We also previewed some of Week 2’s material, mostly just the following simple mathematical operators:

“+” addition, 3 + 5 = 8

“-” subtraction, 10.1 - 6 = 4.1

“*” multiplication, 2 * 2 = 4

“/” division, 11 / 2 = 5.5

There are also two special math operators. The first is “//”, or floor division. This acts like remainder division, but leaves off the remainder. So, 13 // 5 = 2, and 4 // 100 = 0. And “%” is modulo, which acts like remainder division but only says the remainder. So, 5 % 3 = 2, 100 % 50 = 0, 7 % 10 = 7, etc.

We went over these toward the end of class, so we’ll review them at the beginning of Week 2.

Homework

Main Homework Item

Get Python installed and working on your home computer. Instructions on how to do so are located in the “Installing Python” section on the left.

Open up the interactive shell (iPython console or iPython QT console), play around like we did in class!

Lecture Slides