gearBot  

 

Learn to program

 
  GearsBot Python assignments ::

 

 
 

Lesson 12 - Conditional statements

Learning goal: understand the use of conditional statements in a program.

You need to know how to branch in a program, so you can have different results depending on different inputs.

For example, you could program the robot to do different actions when it is light, compared to when it is dark.

conditional

Watch these videos to find out about If-Then (conditional) statements.

This one is a little long, but is a great review, and uses Python 2.

Everyone should watch these:

Python If

Python If-Else

Python If - Elif - Else

Try this video or with a Youtube proxy.

And this one or with a Youtube proxy.

Assignment 12 Part 1

Using this online compiler:

Write a program to ask the user what color they prefer. Give a choice of three colors.

Print something different for each answer.

If you want to have a set of possible options you can use the if...in statement with a
list (options in square brackets separated by commas).

if_in

Use the snipping tool to snip your program, and paste it to a Word document.

Save it to a folder on your computer as ifyourname.

To turn it in, look at the instructions below or watch this video:

  • Go to Google Drive
  • Open the Class Program folder in 'Shared with me'
  • Open your class folder and assignment folder
  • Click on the "New" button on the top left
  • Upload the program from your computer

Assignment 12 Part 2

Watch this lesson video:

Open the simple line follow world and make your robot follow the line.
Try to make it stop before it falls off the world.
(Hint - use the GPS sensor.)

Save it as followYourname;

To turn it in, look at the instructions below or watch this video:

  • Go to Google Drive
  • Open the Class Program folder in 'Shared with me'
  • Open your class folder and assignment folder
  • Click on the "New" button on the top left
  • Upload the program from your computer

 

 

Write a Reflection on what you have learned.