Session 4

  • To use textual Python to control the Rapid Router van

  • Python practice

  • Exploring common errors in Python code

Introduction (5 mins)

  • Slide 1 : What is different? Left: This code makes different moves (left-right-right-left) but always repeats four times Right: This code moves forwards until we reach the destination, we don’t know how many turns that will take.

Python (20 mins)

  • Show slide 4 on the IWB to help participants use the correct Python instructions

  • Use slides 5 - 9 to explore Python and the common errors made. It is important that pupils explore errors in this way, it will help them to deal with them later. Answers:

    • Slide 5: Missing brackets. The round brackets after move_forwards() etc. are essential and the code will not work without them.

    • Slide 6: The names of the commands are also fixed. You cannot miss off a character

    • Slide 7: Missing or incorrect indentation

    • Slide 8: Not defining things that you use, e.g. my.van = Van()

    • Slide 9: Not importing code libraries. Explain that much of Python is built in but when you use special things like the Rapid Router van, you need to import the code. This code isn’t used in most Python programs so it would be inefficient to always include it.

Loops in Python (25 mins)

  • Participants should do levels 93 - 95

  • Use slides 11 - to explore common errors with Python loops.

    • Slide 11: Incorrect indentation. The only thing that indicates whether the code is in a loop or not is the indentation. The line breaks make no difference at all.

    • Slide 12: Missing a colon after the Boolean expression. The colon is essential. It marks the start of the code block that is run in the loop

  • Pupils should then do levels 96 - 100

Summary (5 mins)

Ask participants which important rules they can recall about using Python: indentation, the use of colon, round brackets

Ask pupils if blank lines make any difference, e.g. are the turn_left(), turn_right() and move_forwards() all inside the for loop? Answer: yes, the blank lines don't make any difference.

Homework

  • Participants should finish all Python levels up to 100. Remind them that they can look back to levels 80 - 91 for a reminder about Python syntax.

Last updated