Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
106 views

7 - Simple Raspberry Pi Course

Chris Sharples introduced Raspberry Pis into his classroom by: 1. Creating a Raspberry Pi network with 16 Pis velcroed to walls using a KVM setup. 2. Supporting Digital Leaders to use 17 Pis for a coding club using custom SD cards and kits. 3. Developing Pi activities for Years 8-9 curriculum on input/output and physical computing. Sarah Roman introduced Python programming to her English classes by having students create text adventures based on literature works, marrying English grammar concepts with Python syntax. Both teachers found benefits but also challenges in introducing new technologies which required preparation, resources, and collaboration.

Uploaded by

Jeanpaul Milani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
106 views

7 - Simple Raspberry Pi Course

Chris Sharples introduced Raspberry Pis into his classroom by: 1. Creating a Raspberry Pi network with 16 Pis velcroed to walls using a KVM setup. 2. Supporting Digital Leaders to use 17 Pis for a coding club using custom SD cards and kits. 3. Developing Pi activities for Years 8-9 curriculum on input/output and physical computing. Sarah Roman introduced Python programming to her English classes by having students create text adventures based on literature works, marrying English grammar concepts with Python syntax. Both teachers found benefits but also challenges in introducing new technologies which required preparation, resources, and collaboration.

Uploaded by

Jeanpaul Milani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Simple reaction game using inputs, outputs

and variables
We can start with a very simple program that
involves inputs and outputs and variables
print('Quick, the Enter key')

input()

print('That was fast')

Save your file (File > Save As...) and call it game.py. To run the file
you can just press F5 on your keyboard.

The print functions are a type of output. You are instructing the computer to
display some text on the screen.

The input function takes input from the users keyboard presses.

Lets make the program a little more interesting.

We could make the program pause for a little bit before it starts the game.
Handling time can be a little tricky however, but luckily for us the code to
interface with the computers clock has been written for us and packaged up
into a nice little module that we can use. To start with we only need one
function from the time module. Its called the sleepfunction.
from time import sleep

sleep(5)

print('Quick, press the Enter key')

input()

print('That was fast')


Here you have imported the sleep function from the time module and then
instructed the program to pause for five seconds.

Save and run your code to have a play with your new game.

It would be great to know how quick the user was between seeing the message
and pressing the key. Again, the time module can be used for this, and in
particular a function called time (confusingly!). We can add the import to our
first line.
from time import sleep, time

sleep(5)

print('Quick, the Enter key')

input()

print('That was fast')

The time function will get the number of seconds that have elapsed since
January 1st, 1970. By storing this value in a variable when the message is
displayed, and then subtracting the time again, after the user has pressed a key,
we can work out their reaction time. Here, the reaction time value is stored in
the variable reaction_time. You cant have spaces in variable names,
which is why we often use underscores.
from time import sleep, time

sleep(5)

start = time()

print('Quick, hit the Enter key')

input()

reaction_time = time() - start

print('You took', reaction_time, 'seconds')


Save and run your code then have a play. How fast can you hit that Enter key?

Applied Activity: Working with loops


In Python you can use loops to make lines of code repeat. There are two
types of loop - while loops and for loops. Below you can see examples of
both.
while True:

print('Hello')

input()

This is a while loop which will repeat the indented lines of code until the
condition is no longer true. In this case the condition is just the
value True which will always be True, therefore this loop can never exit.
for i in range(10):

print('Hello')

print(i)

input()

This for loop is a finite loop and will loop a fixed number of times. For each
value from 0 up to (but not including) 10 it will assign the value to the
variable i and carry out the indented lines.

Notice that both loops need colons (:) adding to the end of the line, and four
spaces then need to be placed before the lines of code that are to be repeated.
Try both of the mini programs out to see what the difference is between the two
loops.

HINT : If you need to stop your program running you can press Ctrl + Cto stop
it

Can you use loops in your game to make it repeat?


Can you use variables to store the total reaction time after several games?
Can you work out the average reaction time?
Question 1

Which of these lines of code would require you to import a Python library?

print("test")

input()

sleep(2)

6+6

Correct
Yes, the sleep function is part of the time library and needs importing before
use

You may find 1.11 Simple reaction game using inputs, outputs and
variables useful.

Question 2

What does the following line of Python code do?


reaction_time = time() - start

It finds out the current time, subtracts the variable start and stores the
result in a new variable reaction_time

The reaction_time variable is made equal to the current time and then the value
of start is subtracted.

The current time is subtracted from the variable start and then stored in the
variable reaction_time

CorrectHere is a short program using variables a, b, and c what


will be the values of these variables at the end of the program.
a = 1

b = 4

c = a + b

a = a + 1

b = c - a

a = 2, b = 3, c = 5

a = 2, b = 4, c = 5

a = 1, b = 3, c = 5

a = 1, b = 4, c = 5

Correct
Well done, youve understood how variables are assigned.

You may find 1.11 Simple reaction game using inputs, outputs and
variables useful.

Correct the calculation is carried out and the result stored in the new variable.

You may find 1.11 Simple reaction game using inputs, outputs and
variables useful.

Question 4

What would be the output from this piece of code (you could run it and
see):
for x in range(5):

print(x)
x
x
x
x
x

1
2
3
4
5

0
1
2
3
4

Correct
Yes, the loop will be run 5 times, each time printing the value of x starting at 0

You may find 1.12 Applied Activity: Working with loops useful.

Case Study - Introducing Raspberry Pi


into the Classroom
Introducing any new technology into a classroom brings with it
opportunities but also challenges. Each classroom is different and will
present different challenges and opportunities.
Chris Sharples (Raspberry Pi Certified Educator) attended Picademy, the
Raspberry Pi Foundations free face to face teacher training initiative, in York
during Easter 2015. Chris wanted to attend Picademy because he thought using
Raspberry Pis would be a great way for students to understand how a computer
works, and the GPIO pins have great potential for teaching physical computing.

Chris had a great action plan following Picademy, he wanted to: Goal 1: Create
a Raspberry Pi network Chriss first step to create a Raspberry Pi network was
to move to a bigger classroom. To work out how to fit a half class set (x16)
Raspberry Pis in with 30+ PCs, he got lots of ideas from helpful colleagues on
Twitter, and chose a a KVM setup and Raspberry Pis velcroed to the walls.

Goal 2: Support Digital Leaders to use Raspberry Pis with the lunchtime
Coding Club Chris bid for the money from an education foundation, and with
considerable help from the Digital Leaders, ended up with 17 Raspberry Pis.
Chris then invested a lot of time creating multiple kits and SD cards to use in
class.
Goal 3: Develop activities using the Pi into the KS3 curriculum Chris said The
time and effort paid off as we were able to use the Raspberry Pis for Year 8
and Year 9 (Age 12-14) lessons.

To fully integrate the use of Raspberry Pis in his school, Chris then explored
PiNET, a solution for networking together Raspberry Pi in a classroom. Chris
was inspired to try this system for setting up and managing a classroom set of
Raspberry Pis after having met the creator at and educational conference.

Chriss hard work, fundraising skills and collaboration with the Digital Leaders
has had a big impact on the introduction of physical computing in his school.
Students have a better understanding of how input/process/output works in real-
life systems. They have two hands-on physical computing activities for all
students in Year 8 as part of the curriculum. The Digital Leaders have daily
access to a Raspberry Pi network which they enjoy using, and which Chris can
develop further as computer science develops in his department. Chris is able to
demonstrate an additional resource for a wow factor on open evening to
encourage uptake of computer science.

We cant wait to hear similar stories from educators on this course.

Case Study - Introducing Programming


into the Classroom
Sarah Roman, a Raspberry Pi Certified Educator based in the USA
introduced programming with Python to her English classes.

Sarah works at Raritan High School in Hazlet, New Jersey and teaches six
classes of AP Literature. Sarah started getting into programming in 2013, and
discovered the Raspberry Pi computer as a tech hobbyist. Sarah introduced
programming to her classroom by marrying English grammar with Python.

Its a great way to discuss syntax, diction, structure, word efficiency, and
proofreading.
The project that Sarah has found very beneficial to her students is the text
adventure based upon the book that the students are reading. The text adventure
can be molded to fit any text, but her class used it with King Lear primarily. It
affords the students an interesting way to interact with Python and create their
own universe. As a teacher, she is able to increase or decrease the demands of
the project, for example having the students write in Late Middle English,
working in anachronisms, having certain loops designated to certain in-text
areas or having the students fully argue their story concepts and choices.
Discussion - Using Raspberry Pi and
Python in the classroom
Introducing any new technology into a classroom brings with it
opportunities but also challenges. Each classroom is different and will
present different challenges and opportunities.

Now that youve heard from Chris and Sarah about their experiences wed like
you to consider the steps you might take an challenges you would face?

Use the Discussion below to share your responses to the three articles youve
just read.
Why and how might you use a physical computing device like a
Raspberry Pi in your classroom?
What challenges might you face when introducing a Raspberry Pi
computer to your students?
What solutions can you think of to overcome those challenges or the
challenges of others in the discussion?

You may find our Teachers Guide helpful to your discussions.

Classroom Resources
All of the activities and screencasts you have worked through this week, have
been created for you to use both in this course and in your classroom.

We would be delighted, if you think its useful, for you to take the ideas, links
and resources and adapt them as you see best for your students.

You could download The Raspberry Pi Computer video from


our YouTubechannel to screen in your classroom as you introduce the
Raspberry Pi.
You could screen the connecting all the things gif to demonstrate
plugging in the SD card, power connection and screen, keyboard and
mouse.
The Education team at the Raspberry Pi Foundation create free
resourcesfor your classroom and you may find the Turtley
amazing resource useful with your students to introduce Python.

You might also like