as you come in…

30
As you come in… Sign in (in back) and pick up Badge Name Card – write your first name LARGELY on back Log in: Launch/Start Alice Any questions? (of any kind)

Upload: olaf

Post on 20-Feb-2016

29 views

Category:

Documents


0 download

DESCRIPTION

As you come in…. Sign in (in back) and pick up Badge Name Card – write your first name LARGELY on back Log in: Launch/Start Alice Any questions? (of any kind) . Flow of Control: How Computer Programs are “Executed”. Sequential execution (Do In Order) Parallel execution (Do Together) - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: As you come in…

As you come in… Sign in (in back) and pick up

Badge Name Card – write your first name LARGELY

on back Log in:

Launch/Start Alice Any questions? (of any kind)

Page 2: As you come in…

Flow of Control: How Computer Programs are “Executed”

Sequential execution (Do In Order) Parallel execution (Do Together)

Conditional execution (if/else statement) Powerful for creating programs that don’t

ALWAYS do the same thing Repeated execution (Counted Loop)

Powerful for having the computer repeat our instructions multiple times

TODAY: While loop: Repetition not defined by a specific number (a count) Controlled by Boolean expression (true or false, keep

looping?)

Page 3: As you come in…

Flow of Control: How Computer Programs are “Executed”

Sequential / Parallel execution Conditional execution (if/else statement) Repeated execution (Counted Loop,

While loop)

Page 4: As you come in…

Wrap Up: Nested If Statements

Page 5: As you come in…

Ball Guess Game

Page 6: As you come in…

Practice:“In Class Clicker Discussion Questions”

1) Individual Thinking, Vote2) Group Discussion (with 1-2 other students)3) Group Vote4) Class-Wide Discussion:

a) call on groups to share thinking b) explain yourself (see comments in PPT) OR

show video of my explanation

Pre-Class preparation:Work Through Online ModuleAnswer Embedded QuestionsReflecting Questions (as quiz?)

Page 7: As you come in…

What does this code do?

Assume that you have an event so that when you click on an igloo it calls a my first method and sends the igloo as a parameter

Next we’ll show youmy first method and askyou what it does

Page 8: As you come in…

What does this code do?When blue, red or green…

FeedbackParaphrase

JustifyWorld.my first method

Page 9: As you come in…

How many of the following are true?

1. When the igloo is blue, says Ice Cold! 2. When the igloo is red, says Hot! 3. When the igloo is blue, says Ice Cold!

AND then says Try again!4. When the igloo is green, nothing

happens

Page 10: As you come in…

FeedbackParaphrase

Justify

1. blue, says Ice Cold! 2. red, says Hot! 3. blue, says Ice Cold! AND then says Try

again!4. green, nothing happens

A) 1 B) 2 C)3 D) 4E)

Page 11: As you come in…

BTW: Online Book: Nested Ifs Interactive, Car

drive toward clicked on magnet But only if thing

clicked on IS magnet (9.1-9.3)

Space Ship Take Off But only if all balls

are blue (9.4-9.5)

Page 12: As you come in…

Flow of Control: How Computer Programs are “Executed”

Repeated execution (Counted Loop) Powerful for having the computer repeat

our instructions multiple times TODAY: While loop:

Repetition not defined by a specific number (a count)

Controlled by Boolean expression (true or false, keep looping?)

Page 13: As you come in…

Online Textbook: 10.5: Zombie Chases Lunchlady

Let’s go play the video… Question: When should we “keep

chasing”? Until the zombie catches the lunchLady

OR (said differently) We should first add the condition that,

while it is true, the statements to make the zombie and lunchlady move will repeatedly execute. This condition is: zombie is at least 1 meter from lunchLady.

Let’s code it: Download fromhttp://ce21sandiego.org/2013Meeting 4: Module10.5TeacherStarter.a2w

Page 14: As you come in…

Solution Keep chasing/looping WHILE zombie is

more than 1 meter from the lunchLady

Page 15: As you come in…

Solution Keep chasing/looping WHILE zombie is

more than 1 meter from the lunchLady

Except, yes, this is silly since he always catches her in 3 “steps”

Page 16: As you come in…

Online Textbook 10.5 fixes this… Random turn (0-1 revolution) Random distance for lunchLady and

zombie

Page 17: As you come in…

Visualize in head…

LunchLady

zombie

1 meter

Page 18: As you come in…

What “states” can we have?

LunchLadyzombie

LunchLadyzombie

Page 19: As you come in…

What “states” can we have?

LunchLadyzombie

LunchLadyzombie

1) Should we keep looping?YES

2) Should we keep looping?NO

3) Write boolean expression that evaluatesTo TRUE for situation 1 and FALSE for situation 2

Page 20: As you come in…

Hint to getting while loops right

Humans naturally think “until” I’ll keep spending until I run out of money

(balance <= 0) I’ll keep dancing until I fall asleep

Computers use “while” loops – the opposite I’ll keep spending while I still have money

(balance > 0) I’ll keep dancing while I am not asleep While I have a dirty dish, I’ll keep washing

dishes

Page 21: As you come in…

Let’s have a race… A

Wind up penguin (he just goes) While loop with “walk and spin” inside it

Jet-pack penguin2 (controlled by <- event) Moves forward .5 meters

Race to a stop sign (within 2 meters) Whenever someone gets within 2 meters

Stop looping (going)

Page 22: As you come in…

While loops in Alice tend to be used when…

You have a user controlled (hence, not predictable) event So you don’t know when the user might

Click on an object Type a key, User types a number (pick a number between

1-10, etc. You have (not predictable) actions

controlled by, for example, random numbers E.g. the lunchlady/zombie or fish/shark case

Page 23: As you come in…

When should we keep going?e.g. while loop expression true(P1: wind up, P2: jet pack)

Cases A B C DP1, P2 outside T T T TP1 inside, P2 outside T T T FP2 inside, P1 outside T T F FP1, P2 inside T F F F

Page 24: As you come in…

Which while loop header (tile) would you use to control the “going”?

Page 25: As you come in…

Let’s Build the Code! Download from http://ce21sandiego.org/2013

Meeting 4: JetPackPenguinTeacherStart.a2w Plan:

Explore object positions Create event that moves jet pack penguin 0.5 meters

whenever <space> is pushed. (Test) SIMPLIFY: Create loop that makes windup penguin

move repeatedly (forever), 0.35 meters (at same time as “walks” and windupKey “rolls” 0.25 revolutions)

CORRECT: change loop to have the game end (e.g. windup penguin stops walking) when either penguin “wins” (gets within 2 meters of stop sign)WHILE:_________________________________________

Page 26: As you come in…

This would STOP the game (evaluate to false) whenA. Both penguins must be close to the stop

signB. Either penguin is close to the stop signC. Neither penguin is close to the stop signD. I don’t know

What does the other one do?

Page 27: As you come in…

Cases E1 E2

Evaluates To (keep playing while true)

P1, P2 outside T TP1 inside, P2 outside

F T

P2 inside, P1 outside

T F

P1, P2 inside F FTruth Table for OR logical operator

Page 28: As you come in…

Cases E1 E2

Evaluates To(keep playing while true)

P1, P2 outside T TP1 inside, P2 outside

F T

P2 inside, P1 outside

T F

P1, P2 inside F FTruth Table for AND logical operator

Page 29: As you come in…

Useful tool: “Life points” Use: to keep track of “points” in a game 2 “cylinder” objects set on top of each

other Grey is “background” Yellow is in “front”

Yellow moves down a bit each time “you lose a point”

The game is over when the yellow cylinder is Distance to the ground >= cylinder height. (So while not, game is ongoing…)

Page 30: As you come in…

Coming Up… Week 5: Compound Boolean Expressions

and if statements and while loops Week 6: Functions, Mathematical

expressions, parameters, methods Week 7: Functions, parameters, methods

and events Week 8: Lists