Summary of Stage 2 Lessons

Lesson 1: Introduction to "Serious" Programming

Computers

Computers can be programmed to do anything we want, as long as we can write a program that specifies a specific sequence of instructions.

Computer Program

A program is a precise sequence of steps that a computer can follow to do something useful. Web browsers, games, mobile apps, and simple print statements are all examples of computer programs.

Programming Language

A programming language is what programmers use to tell a computer what to do. Python is one example of a programming language.

Python

Python is a programming language. When you write Python code and press "Run", a Python Interpreter converts the code you wrote as a set of instructions that the computer itself can understand and execute.

Python language is case sensitive.

Grammar

A grammar is a specification of what is "correct" and what is "incorrect." We have to write code that is exactly "correct" according to the Python interpreter, otherwise our code won't run.

Python Expressions

A Python "expression" is a legal Python statement. For example: print 1 + 1 is a valid expression, but print 1 + (without a number at the end) is not.

Lesson 2: Variables and Strings

What is a variable in Python?

Variables give programmers a way to give names to values.

What does it meant to assign a value to a variable? How is it done?

We can assign the value 2 to the variable my_variable

We can even change the value of a variable by re-assigning it to a different value later.

What's the difference between what the equals sign means in 2 + 3 = 5 and my_variable = 5?

In the line 2 + 3 = 5, the equals sign means "is the same as".

In the line my_variable = 5, the equals sign means "takes the value of".

What are some ways variables are useful?

  • They improve code readability by using names that make sense to humans.
  • They give us a way to store the value of important data.
  • They give us a way to change the value of something (like in the line days = days-1)

What is the difference between 2 + 2 and "2" + "2" ?

In Python, 2 is a number while "2" is a string.

The code 2 + 2 would give 4.

The code "2" + "2" would give "22".

Lesson 3: Input -> Function -> Output

What is a function (Dave calls them "pro cedures")?

A function is something that takes input, does something to that input, and then produces output.

What is the difference between making and using a function?

Functions are made by starting a line of code with the keyword def and then giving a function name followed by the function parameters in parentheses. These parameters will eventually be replaced by actual values when the function is used (called).

In the "body" of the function, we write the code that specifies what to do with the input parameters.

To use a function, we write the name of the function followed by the value(s) we want to give it in parentheses.

How do functions help programmers avoid repetition?

Functions are tools that programmers can create and reuse forever! Once you've defined a function once, you never have to define it again.

What happens if a function doesn't have a return statement?

The return keyword tells Python exactly what the function should produce as output. If a function doesn't have a return statement,computer won't do anything. It will return "None" as result.

Lesson 4: Control Flow & Loops:If and While

What is IF...ELSE Statement?

The syntax of the if...else statement is −
if test expression:
    statement(s)
else:
    statement(s)

For IF statement, computer will return Boolean result-True or False. If condition is true, it will execute if code;otherwise, it will execute else code.

What is the While Statement?

While is a loop statement. A loop statement allows us to execute a statement or group of statements multiple times.

While loop repeats a statement or group of statements while a given condition is TRUE. It tests the condition before executing the loop body.

What is the Break Statement?

Break Statement terminates the loop statement and transfers execution to the statement immediately following the loop.

Lesson 5: Debugging

What is debugging?

Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program.

  1. Examine error messages when programs crash
  2. Work from example code
  3. Make sure examples work
  4. Check (print) intermediate results
  5. Keep and compare old versions

Lesson 6: Structured Data: Lists & For Loops

For Loops

Lists are sequences of data.

For Loops allow you to iterate over Lists.

RETURN TO TOP