Week 2: Session 1
Variables, Logical Operators and Expressions
Activity 1: Review Week 1
- Parts of the computer
- Visual Studio Code: IDE Interactive Development Environment
- Python
- Program
- Programming a challenge
Activity 2: Introduce How to Make Decisions inside a program
Variables have a name and a value. Decisions are made by testing the value of variables. Variable can be named anything you want with a few exceptions because computers are picky. Variable types determine how logical comparisons will work.
- Types: String, Number, Boolean
- Comparisons: ==, !=, <=, >=, <, >
- Logical Operators: AND, OR, and NOT
Activity 3: Practice writing code that uses variables with different types
Create a variable with any name you want and assign a value. Make variables for each of the types. Notice strings have to have quotes around them.
num = 1
str = "Hi"
bool = TRUE
Activity 4: Practice writing code that tests for values of different types
write code that tests if they are a certain value.
Use the "if" instruction to set up a decision. Put the test in parentheses.
if (num == 2) print ("true")
if (num == 1) print ("true")
Activity 5: Write a program that asks for a name and then tests to see if it's your name
print ("What's your name?")
In the first activity for this week, we introduce the comparison and logcial operators which can be used to make decisions inside a program which depends on the values in variables. These operators rely on the idea of the boolean type, in which there are only two value: TRUE and FALSE. Comparison operators can compare the values of two variables with respect to equality (==, !=, <=, >=, <, >) and return a boolean value. Logical operators (AND, OR, and NOT) are used to compare boolean values.
We'll use Comparison and Logical operators with the "for" loop and the "while" loop to run instructions multiple times. The operators will help the code decide when to start and stop a loop.
We'll do exercises in which we write code that uses the comparison and logical operators as well as the loops. We'll also see how the game framework uses the loops to control the flow of the game. We'll also learn to write Challenges that can be associated with an Episode in the game.
Activity 6: Introduce the Adventure Game and add a Challenge
In the final activity for the week, we introduce the Adventure Game framework and students write a challenge using the "print" statement.
Activity 7: Write a Challenge for the game
Write a challenge that asks a question and tests the value of the answer