Search icon CANCEL
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Raspberry Pi Projects for Kids

You're reading from  Raspberry Pi Projects for Kids

Product type Book
Published in Mar 2014
Publisher
ISBN-13 9781783982226
Pages 96 pages
Edition 1st Edition
Languages
Author (1):
Daniel Leonard Bates Daniel Leonard Bates
Profile icon Daniel Leonard Bates

Coding the game


Here's a quick recap on how this example game is going to work. The Raspberry Pi will choose a random button and ask the player to press it. Every time the player presses the right button, they get a point, and every time they press a wrong button, they lose a point. Once the right button has been pressed, the Raspberry Pi selects a new button as the target. The aim is to score as many points as possible in 30 seconds.

In IDLE, navigate to File | New Window. This will bring up a new empty window, which is where all our code will go. This window is better for editing existing code, and I will call it the Edit window. Whenever you want to test or run your code, navigate to Run | Run Module, or press F5 on your keyboard. This will take you back to the first window, which I will call the Shell, with the code ready to run.

Random behavior

The first job, then, is to write some code that will choose a random button for the player to press. Take a look at the following code snippet...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}