Switching from Blockly to Python (visual to text language)
Objectives
Develop an initial understanding of Python as a text-based language
Understand that Python has precise syntax
Identify characteristics of Python, compare this with Blockly
Use and understand the movement instructions in Python code
Use and understand repeat loops in Python (for count in range(number))
80. Here's Python
81. Matching Blockly
82. Don't forget to find the shortest route
83. Repeating yourself in Python looks different!
84. Repeat and watch
UKS3–S12
Understanding more Python commands (while, if.. elif..else)
Objectives
Create the core program in visual Blockly and convert it to Python
Understand how the syntax of selection statements works in Python
Understand the Python while, if... elif... else commands
Analyse how procedures work in Python (extension)
85. Looks easy but use repeat until and see what happens?
86. See what the if blocks look like in Python
87. Don't forget to use else if
88. See what happens when you add traffic lights
89. Watch carefully as you have another go
90. Have a go at procedures - what do they look like in Python?
91. Put it all together
UKS3–S13
Writing basic code directly in Python (forwards, turn, print, repetition)
Objectives
Write code in Python without the support of Blockly
Write simple programs in Python using code for simple movement e.g. my_van.move_forwards()
Use the print command in Python (not available in Blockly)
Debug their Python programs, demonstrating an understanding of the appropriate syntax
Use indents correctly in Python
Use the Repeat loop … for count in range(number):
92. Start with the basics; forward, left and right
from van import Vanmy_van =Van()my_van.move_forwards()my_van.turn_right()my_van.turn_left()my_van.move_forwards()
93. Keep it simple
from van import Vanmy_van =Van()my_van.turn_left()my_van.move_forwards()my_van.move_forwards()my_van.turn_right()my_van.turn_right()my_van.turn_left()my_van.turn_right()my_van.move_forwards()my_van.move_forwards()my_van.turn_left()my_van.turn_left()my_van.turn_right()
94. Take the shortest route
from van import Vanmy_van =Van()my_van.turn_right()my_van.turn_left()my_van.move_forwards()my_van.turn_right()my_van.turn_left()my_van.turn_right()my_van.turn_left()
95. Count and repeat
from van import Vanmy_van =Van()for i inrange(3): my_van.turn_left() my_van.turn_right() my_van.move_forwards()
96. Count and repeat is easy
from van import Vanmy_van =Van()for count inrange(2): my_van.move_forwards()my_van.turn_left()for count inrange(3): my_van.move_forwards()
97. Loop the Loop
from van import Vanmy_van =Van()for count inrange(3):for forward inrange(4): my_van.move_forwards()for left inrange(2): my_van.turn_left()for forward inrange(4): my_van.move_forwards()for right inrange(2): my_van.turn_right()
UKS3–S14
Flying solo with Python! (programming independently using repetition and selection, extension to using procedures – several lessons)
Objectives
Design and write programs independently in Python using repetition and selection: for count in range (number): and while, if... elif... else
Debug Python programs, demonstrating an understanding of the appropriate syntax
Use indents correctly in Python
Use comments in Python to explain how the program works.
Extension objectives
Defining new procedures in Python (also called functions)
98. Repeat and check
from van import Vanmy_van =Van()whilenot my_van.at_destination():if my_van.is_road_forward(): my_van.move_forwards()else: my_van.turn_left()
99. Find a general solution
from van import Vanmy_van =Van()whilenot my_van.at_destination():if my_van.is_road_forward(): my_van.move_forwards()elif my_van.is_road_left(): my_van.turn_left()else: my_van.turn_right()
100.Watch out for the dead end
from van import Vanmy_van =Van()whilenot my_van.at_destination():if my_van.is_road_forward(): my_van.move_forwards()elif my_van.is_road_left(): my_van.turn_left()else: my_van.turn_right()
101. Function, what function?
from van import Vanmy_van =Van()defright_left(): my_van.turn_right() my_van.turn_left()right_left()my_van.move_forwards()right_left()for count inrange(2): my_van.move_forwards()for count inrange(2):right_left() my_van.turn_right()my_van.move_forwards()
102. Watch for the patterns
from van import Vanmy_van =Van()defleft():for count inrange(2): my_van.turn_left() my_van.turn_right()defright():for count inrange(2): my_van.turn_right() my_van.turn_left()left()right()my_van.move_forwards()my_van.turn_right()for count inrange(2): my_van.move_forwards()my_van.turn_right()right()left()my_van.move_forwards()
103. Patterns within patterns
from van import Vanmy_van =Van()defforward_left(): my_van.move_forwards() my_van.turn_left()defforward_right(): my_van.move_forwards() my_van.turn_right()defbig():forward_left()for count inrange(2):forward_right()big()my_van.move_forwards()big()forward_left()for count inrange(2):forward_right() my_van.move_forwards()forward_left()
104. Can you see the repeating pattern?
from van import Vanmy_van =Van()defleft():for count inrange(2): my_van.move_forwards() my_van.turn_left()defright():for count inrange(2): my_van.move_forwards() my_van.turn_right()defbig():left()right()big()for count inrange(4): my_van.move_forwards()right()big()for count inrange(3): my_van.move_forwards()my_van.turn_right()my_van.turn_left()left()my_van.move_forwards()
105. Find the shortest route
from van import Vanmy_van =Van()whilenot my_van.at_destination():if my_van.at_red_traffic_light(): my_van.wait()elif my_van.is_road_left(): my_van.turn_left()elif my_van.is_road_forward(): my_van.move_forwards()else: my_van.turn_right()
UKS3–S15
Creating new Python variables, incrementing variables
Objectives
Design and write programs independently in Python using repetition and selection: for count in range (number): and while, if... elif... else
Debug Python programs, demonstrating an understanding of the appropriate syntax
Use indents correctly in Python
Creating and incrementing variables
Use comments in Python to explain how the program works.
106. Spiral and add
from van import Vanmy_van =Van()number =1whilenot my_van.at_destination(): my_van.turn_right()for count inrange(number): my_van.move_forwards() number = number +1
107. Spiral and double
from van import Vanmy_van =Van()number =1whilenot my_van.at_destination(): my_van.turn_left()for count inrange(number): my_van.move_forwards() number = number *2
108. Think less
from van import Vanmy_van =Van()number =6whilenot my_van.at_destination():for i inrange(number): my_van.move_forwards() my_van.turn_left() number = number -2
109. Final challenge!
from van import Vanmy_van =Van()number =0for count inrange(4): my_van.turn_right()for forward inrange(number): my_van.move_forwards() number = number +1my_van.turn_right()whilenot my_van.at_destination():for count inrange(number): my_van.move_forwards() my_van.turn_left() number = number /2