Lesson 15: Conditionals with the Farmer
60 minutes
Overview
This skill-building lesson focuses on a new type of programming puzzle, featuring a farmer who needs to prepare her fields for planting crops.
Purpose
This lesson introduces students to while loops and "if / else" statements.
Standards
AP - Algorithms & Programming
- 1B-AP-11 - Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.
Agenda
Objectives
Students will be able to:
- Define circumstances when certain parts of a program should run and when they shouldn't.
- Determine whether a conditional is met based on criteria.
Preparation
- Play through the puzzles to find any potential problem areas for your class.
- Make sure every student has a reflection journal.
Links
Heads Up! Please make a copy of any documents you plan to share with students.
For the teachers
- Pause and Think Online - Video
Vocabulary
- Condition - Something a program checks to see if it is true before allowing an action.
- Conditionals - Statements that only run under certain conditions.
- While Loop - A loop that continues to repeat while a condition is true.
Teaching Guide
Warm Up (15 minutes)
Introduction
Gather the class together and ask two volunteers to walk straight in some direction in the classroom. If they encounter a chair out of place, they must step over it. If they reach a wall, they must sit down.
Once all of the students are sitting down, ask how you would program a robot to respond to a wall or a chair. Remind students that you cannot simply say "Step over chair" unless you know there is a chair, and you will not always know there is a chair. It might be helpful to translate the task into instructions like:
- while there is a path ahead
- walk forward
- if there is a chair, step over it
- sit down
Tell students they will be using conditionals to solve this problem on Code.org. Give the definition of:
- Condition: A statement that a program checks to see if it is true or false. If true, an action is taken. Otherwise, the action is ignored.
- Conditionals: Statements that only run under certain conditions.
Open up a discussion of when you might use a conditional in your code.
Main Activity (30 minutes)
Conditionals with the Farmer
The patterns in these puzzles may not be obvious to every student. We recommend that you play through these levels beforehand to best understand any problem areas for your class. Also, watching and using the techniques from *Pause and Think Online Video may be helpful for your class.
Wrap Up (15 minutes)
Reflection
Prompts:
- What is a conditional? Why would you program a conditional?
- Give an example of using a conditional during your day? (ex. If I am hungry, I eat some food; While I am walking across the street, I keep an eye out for cars)
Extended Learning
Use these activities to enhance student learning. They can be used as outside of class activities or other enrichment.
While We Play
Gather the class for some fun outside or in a gym with a ball! This could be done in a circle or as a team in a court
Rules:
- While the ball is in play, we must all be ready to hit it
- If the ball is hit to you, you must keep it in the air
- If you hit the ball once, you cannot hit it again (only one touch per person per turn, no double hitting)
- If the ball goes out of bound, every student must fall to the ground dramatically. The last kid to fall has to retrieve the ball.
At the end of the first round, ask the students if they can identify the conditionals in the game. Can they come up with others they might want in the game?
This work is available under a Creative Commons License (CC BY-NC-SA 4.0).
If you are interested in licensing Code.org materials for commercial purposes contact us.