Week 1 – Beginners Content McAfee & Big Fish Games CoderDojo.
Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type...
Transcript of Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type...
![Page 1: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/1.jpg)
![Page 2: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/2.jpg)
Our First Script
Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter
To run it type
![Page 3: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/3.jpg)
Controlling the robot In your shared folder there’s a script called robot.py When this is run it will drive the robot forward for 5 seconds. The commands to move the robot are robot.forward() robot.stop() robot.backward() robot.right() robot.left() The sleep function is used to control the amount of time the robot spends on each movement. sleep()
![Page 4: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/4.jpg)
Today’s Challenges
Obstacle course
![Page 5: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/5.jpg)
Last week we moved our robots by an amount of seconds but it would be a lot simpler if we could use
say Centimetres
Just as Python comes with pre-written functions we can also write our own functions
The advantages of using our own functions are • The program is easier to understand. • You can reuse code easily. • Easier to design and test code.
![Page 6: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/6.jpg)
What do functions do 1. It can take in Data (called Arguments) 2. It can perform some computational task. 3. It can return a result and/or modify parameters.
A function's definition is where we write the code for our function has to come before you call the function. We call our own functions the same way we call Python’s built in functions.
![Page 7: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/7.jpg)
Writing A Function The def statement
The def statement is made up of the def keyword, followed by a function name with parentheses, and then a colon (the : sign). There is a block after the statement called the def-block. The code in this block is executed when we call the dist_to_time() function later in the program.
![Page 8: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/8.jpg)
Our def Block
![Page 9: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/9.jpg)
Return
This is the return keyword, which only appears inside def-blocks. It will send values back to our main program. Functions with return values are normally called like this
![Page 10: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/10.jpg)
![Page 11: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/11.jpg)
![Page 12: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/12.jpg)
![Page 13: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/13.jpg)
![Page 14: Our First Script - CoderDojo Athenry | CoderDojo … First Script Log in to Putty At the prompt type Then type Then press Ctrl + X Then press y followed by Enter To run it type Controlling](https://reader031.fdocuments.in/reader031/viewer/2022022003/5a9ff8337f8b9a76178d74f0/html5/thumbnails/14.jpg)