SlideShare una empresa de Scribd logo
1 de 38
Descargar para leer sin conexión
PLATINUM)SPONSORS)

GOLD)SPONSORS)

SILVER)SPONSORS)

Saturday, May 4, 13
Teach your kids how to
program with Python
and the Raspberry Pi
Juan Gomez
Co-Founder of PyhtonKC
Twitter: @_juandg

Saturday, May 4, 13
May the 4th be with you!
Saturday, May 4, 13
So what is this talk really about?
Saturday, May 4, 13
Brief History of the RaspberryPi
More at: https://www.youtube.com/watch?v=z-j4USHTLWM
Saturday, May 4, 13
Saturday, May 4, 13
What you’ll
need:
• MicroUSB Power Supply
• SD Card (>= 4GB)
• USB Keyboard
• USB Mouse
• Ethernet Cable
• HDMI Cable
• Monitor
• Case?
• HDMI to VGA Adapter?
• USB WiFi Adapter?
• USB to TTL Cable?
• RCA Cable?
Saturday, May 4, 13
How do you teach
kids?

Saturday, May 4, 13
Make it fun!
http://www.adafruit.com/products/975
Saturday, May 4, 13
Some tips
• Seriously, Make it fun!
• Start with Math
• Be Patient
• Explain the Basics
• Use real life examples
• Kids are slow typists!
Saturday, May 4, 13
How do I set it up?

Saturday, May 4, 13
Saturday, May 4, 13
Disclaimer
• This an intro to Python for YOU, not your
kids.

• The kids version is at: https://github.com/
mechanicalgirl/young-coders-tutorial

Saturday, May 4, 13
A Python Code Sample
x = 34 - 23
# A comment.
y = “Hello”
# Another one.
z = 3.45
if z == 3.45 or y == “Hello”:
x = x + 1
y = y + “ World”
# String concat.
print x
print y

Saturday, May 4, 13
Enough to Understand the Code
• First assignment to a variable creates it
• Assignment is = and comparison is ==
• For numbers + - * / % are as expected
• Special use:
• + for string concatenation
• % for string formatting (as in C’s printf)

• Logical operators are words (and, or, not)
not symbols (&&, ||, !).
• The basic printing command is print

Saturday, May 4, 13
Comments
• Start comments with #, rest of line is ignored
• Can include a “documentation string” as the first
line of a new function or class you define
• Development environments, debugger, and other
tools use it: it’s good style to include one
def my_function(x, y):
“““This is the docstring. This
function does blah blah blah.”””
# The code would go here...

Saturday, May 4, 13
Python and Types

• Everything is an object!
• “Dynamic Typing”->
• “Strong Typing” ->
x = “the answer is ”
y = 23
print x + y

Saturday, May 4, 13

Data types determined automatically.
Enforces them after it figures them out.

# Decides x is string.

# Decides y is integer.
# Python will complain about this.
Basic Datatypes
• Integers (default for numbers)
•z = 5 / 2 # Answer 2, integer division

• Floats
•x = 3.456

• Strings
• Can use “” or ‘’ to specify with “abc” == ‘abc’
• Unmatched can occur within the string: “matt’s”
• Use triple double-quotes for multi-line strings or strings that
contain both ‘ and “ inside of them:
“““a‘b“c”””

Saturday, May 4, 13
Whitespace
Whitespace is meaningful in Python: especially
indentation and placement of newlines
•Use a newline to end a line of code
Use  when must go to next line prematurely

•No braces {} to mark blocks of code, use
consistent indentation instead
• First line with less indentation is outside of the block
• First line with more indentation starts a nested block

•Colons start of a new block in many constructs,
e.g. function definitions, then clauses

Saturday, May 4, 13
Assignment

•You can assign to multiple names at the
same time
>>> x, y = 2, 3
>>> x
2
>>> y
3

This makes it easy to swap values
>>> x, y = y, x

•Assignments can be chained
>>> a = b = x = 2
Saturday, May 4, 13
A Python Code Sample
x = 34 - 23
# A comment.
y = “Hello”
# Another one.
z = 3.45
if z == 3.45 or y == “Hello”:
x = x + 1
y = y + “ World”
# String concat.
print x
print y

Saturday, May 4, 13
Side by Side with Java
Java (C#)
public class Employee
{
private String myEmployeeName;
private int
myTaxDeductions = 1;
private String myMaritalStatus = "single";

Python
class Employee():

def __init__(self,

public Employee(String EmployeName)
{
this(EmployeName, 1);
}

employeeName

public Employee(String EmployeName, int taxDeductions)
{
this(EmployeName, taxDeductions, "single");
}
public Employee(String EmployeName,
int taxDeductions,
String maritalStatus)
{
this.myEmployeeName
= EmployeName;
this.myTaxDeductions
= taxDeductions;
this.myMaritalStatus
= maritalStatus;
}

):

}

Saturday, May 4, 13

, taxDeductions=1
, maritalStatus="single"

self.employeeName

= employeeName

self.taxDeductions

= taxDeductions

self.maritalStatus

= maritalStatus
Life is Short
(You Need Python)
- Bruce Eckel (Thinking in C++)

Saturday, May 4, 13
Useful books:
Python for Kids
http://oreil.ly/10boyUq
The Quick Python Book, 2nd Ed
http://amzn.to/lXKzH5

Google's Python Class
https://developers.google.com/edu/python/

Saturday, May 4, 13
Let’s start by writing
text based games

Saturday, May 4, 13
Saturday, May 4, 13
A Skeleton
• Let’s start with the most basic pygame program
template.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

from pygame import *
from pygame.sprite import *
from random import *
init()
screen = display.set_mode((640, 480))
display.set_caption('Window name!')
while True:
e = event.poll()
if e.type == QUIT:
quit()
break

Saturday, May 4, 13

screen.fill(Color("white"))
display.update()
Surface
• Most of the game elements you see are represented as
Surface
• display.set_mode((x, y)) creates your canvas – it
returns a Surface object
Useful surface methods:
• fill("color") fills the surface object it's been called from
• blit(surface, area) paints the source surface onto the
rectangle bounded by the area tuple
– Example: screen.blit(ball, (50,50))
Saturday, May 4, 13
Rect
• Objects that store rectangular coordinates
• Call .get_rect()on a surface to get its bounding box
Rectangle methods/variables:
• .center holds the object's center as a tuple
• .colliderect(target) returns True if the parameter
overlaps with the object
• .collidepoint(target) returns True if the target point
overlaps with the object
Saturday, May 4, 13
Media
• Loading an image:
– img = image.load("file.gif").convert()

• Getting a bounding rectangle:
– img_rect = img.get_rect()

• Loading and playing a sound file:
– mixer.Sound("file.wav").play()

Saturday, May 4, 13
Sprite
• Simple base class visible game objects inherit from.
Ball.py
1
2
3
4
5
6
7
8
9
10
11

from pygame import *
from pygame.sprite import *
class Ball(Sprite):
def __init__(self):
Sprite.__init__(self)
self.image = image.load("ball.png").convert()
self.rect = self.image.get_rect()

Saturday, May 4, 13

def update(self):
self.rect.center = mouse.get_pos()
Using Sprites
• They're just objects: initialize them
– ball = Ball()

• Create a group of sprites in main
– sprites = RenderPlain(sprite1, sprite2)

• Groups know how to draw and update
– sprites.update()
– sprites.draw(surface)

Saturday, May 4, 13
Events
• User input such as clicking, moving mouse or key presses
• Add more branches to test the result of event.poll()
• Events to test for:
– QUIT
– MOUSEBUTTONDOWN
– JOYBUTTONDOWN

• Testing for the letter ‘d’ being pressed using KEYDOWN
if e.type == KEYDOWN:
if e.key == K_d:
…

Saturday, May 4, 13
Adding Text
• f = font.Font(font, size) goes before your game loop
– Example: f = font.Font(None, 25)
– Usually, None is a good enough font!

• text = Font.render(text, antialias, color)
– Example: text = f.render("Hello!", True,
Color("green"))
– Returns a surface

• Must be blit, just like any other surface
– Example: screen.blit(t, (320, 0))

Saturday, May 4, 13
Let’s dissect a game!

Saturday, May 4, 13
Join PythonKC -> http://
www.meetup.com/pythonkc/
Saturday, May 4, 13
Thanks!
Juan Gomez
Co-Founder of PyhtonKC
Twitter: @_juandg

Saturday, May 4, 13
PLATINUM)SPONSORS)

GOLD)SPONSORS)

SILVER)SPONSORS)

Saturday, May 4, 13

Más contenido relacionado

La actualidad más candente

Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!Fariz Darari
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programmingDamian T. Gordon
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdfCBJWorld
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonNowell Strite
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Fariz Darari
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019Samir Mohanty
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
 
Basics of Computer Coding: Understanding Coding Languages
Basics of Computer Coding: Understanding Coding LanguagesBasics of Computer Coding: Understanding Coding Languages
Basics of Computer Coding: Understanding Coding LanguagesBrian Pichman
 
Programming in Python
Programming in Python Programming in Python
Programming in Python Tiji Thomas
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Edureka!
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript TutorialBui Kiet
 
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaPython Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaEdureka!
 

La actualidad más candente (20)

Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
 
Introduction to Python programming
Introduction to Python programmingIntroduction to Python programming
Introduction to Python programming
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
python lab programs.pdf
python lab programs.pdfpython lab programs.pdf
python lab programs.pdf
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019
 
Python
PythonPython
Python
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Basics of Computer Coding: Understanding Coding Languages
Basics of Computer Coding: Understanding Coding LanguagesBasics of Computer Coding: Understanding Coding Languages
Basics of Computer Coding: Understanding Coding Languages
 
Programming in Python
Programming in Python Programming in Python
Programming in Python
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
Computer Programming- Lecture 5
Computer Programming- Lecture 5 Computer Programming- Lecture 5
Computer Programming- Lecture 5
 
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaPython Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 

Destacado

Python for the C# developer
Python for the C# developerPython for the C# developer
Python for the C# developerMichael Kennedy
 
Python Programming Essentials - M2 - Introduction to Python
Python Programming Essentials - M2 - Introduction to PythonPython Programming Essentials - M2 - Introduction to Python
Python Programming Essentials - M2 - Introduction to PythonP3 InfoTech Solutions Pvt. Ltd.
 
From Prospect To Production In 30 Days
From Prospect To Production In 30 DaysFrom Prospect To Production In 30 Days
From Prospect To Production In 30 DaysE Carter
 
java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part iijyoti_lakhani
 
Python Is Rad
Python Is RadPython Is Rad
Python Is RadE Carter
 
“Learn the fundamental of programming with animals and robots” - Edu 3.4
“Learn the fundamental of programming with animals and robots” - Edu 3.4“Learn the fundamental of programming with animals and robots” - Edu 3.4
“Learn the fundamental of programming with animals and robots” - Edu 3.4eLearning Consortium 電子學習聯盟
 
Teaching Kids Programming using Agile Practices
Teaching Kids Programming using Agile PracticesTeaching Kids Programming using Agile Practices
Teaching Kids Programming using Agile PracticesLynn Langit
 
共享創意知多D及如何利用共享創意分享教材與創作 - 校本經驗分享 - Edu 3.4
共享創意知多D及如何利用共享創意分享教材與創作 - 校本經驗分享 - Edu 3.4共享創意知多D及如何利用共享創意分享教材與創作 - 校本經驗分享 - Edu 3.4
共享創意知多D及如何利用共享創意分享教材與創作 - 校本經驗分享 - Edu 3.4eLearning Consortium 電子學習聯盟
 
CON 3431 - Introducing Java Programming to Kids
CON 3431 - Introducing Java Programming to KidsCON 3431 - Introducing Java Programming to Kids
CON 3431 - Introducing Java Programming to KidsArun Gupta
 
Hour of code computer science class
Hour of code computer science classHour of code computer science class
Hour of code computer science classHolly Akers
 
Ch 30 Nature of theAtom
Ch 30 Nature of theAtomCh 30 Nature of theAtom
Ch 30 Nature of theAtomScott Thomas
 

Destacado (20)

Python for the C# developer
Python for the C# developerPython for the C# developer
Python for the C# developer
 
Python Programming Essentials - M2 - Introduction to Python
Python Programming Essentials - M2 - Introduction to PythonPython Programming Essentials - M2 - Introduction to Python
Python Programming Essentials - M2 - Introduction to Python
 
From Prospect To Production In 30 Days
From Prospect To Production In 30 DaysFrom Prospect To Production In 30 Days
From Prospect To Production In 30 Days
 
java programming basics - part ii
 java programming basics - part ii java programming basics - part ii
java programming basics - part ii
 
Python Is Rad
Python Is RadPython Is Rad
Python Is Rad
 
“Learn the fundamental of programming with animals and robots” - Edu 3.4
“Learn the fundamental of programming with animals and robots” - Edu 3.4“Learn the fundamental of programming with animals and robots” - Edu 3.4
“Learn the fundamental of programming with animals and robots” - Edu 3.4
 
Modernize your existing teaching materials through Office 365
Modernize your existing teaching materials through Office 365Modernize your existing teaching materials through Office 365
Modernize your existing teaching materials through Office 365
 
“Performance Analytics and Assessment for Learning” - Edu 3.4
“Performance Analytics and Assessment for Learning” - Edu 3.4“Performance Analytics and Assessment for Learning” - Edu 3.4
“Performance Analytics and Assessment for Learning” - Edu 3.4
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Teaching Kids Programming using Agile Practices
Teaching Kids Programming using Agile PracticesTeaching Kids Programming using Agile Practices
Teaching Kids Programming using Agile Practices
 
Kids liketocode
Kids liketocodeKids liketocode
Kids liketocode
 
「有機上網」了,然後呢? - Edu 3.4
「有機上網」了,然後呢? - Edu 3.4「有機上網」了,然後呢? - Edu 3.4
「有機上網」了,然後呢? - Edu 3.4
 
"Google雲端學習:跳出校園輕鬆教學" - Edu 3.4
"Google雲端學習:跳出校園輕鬆教學" - Edu 3.4"Google雲端學習:跳出校園輕鬆教學" - Edu 3.4
"Google雲端學習:跳出校園輕鬆教學" - Edu 3.4
 
共享創意知多D及如何利用共享創意分享教材與創作 - 校本經驗分享 - Edu 3.4
共享創意知多D及如何利用共享創意分享教材與創作 - 校本經驗分享 - Edu 3.4共享創意知多D及如何利用共享創意分享教材與創作 - 校本經驗分享 - Edu 3.4
共享創意知多D及如何利用共享創意分享教材與創作 - 校本經驗分享 - Edu 3.4
 
CON 3431 - Introducing Java Programming to Kids
CON 3431 - Introducing Java Programming to KidsCON 3431 - Introducing Java Programming to Kids
CON 3431 - Introducing Java Programming to Kids
 
Hour of code computer science class
Hour of code computer science classHour of code computer science class
Hour of code computer science class
 
Learning with Lenovo - Edu 3.4
Learning with Lenovo - Edu 3.4Learning with Lenovo - Edu 3.4
Learning with Lenovo - Edu 3.4
 
Ch 30 Nature of theAtom
Ch 30 Nature of theAtomCh 30 Nature of theAtom
Ch 30 Nature of theAtom
 
“Can we deface your Web in 10 mins?” - Edu 3.4
“Can we deface your Web in 10 mins?” - Edu 3.4“Can we deface your Web in 10 mins?” - Edu 3.4
“Can we deface your Web in 10 mins?” - Edu 3.4
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 

Similar a Teach your kids how to program with Python and the Raspberry Pi

Scalable JavaScript
Scalable JavaScriptScalable JavaScript
Scalable JavaScriptYnon Perek
 
Introduction to Python and Web Programming
Introduction to Python and Web ProgrammingIntroduction to Python and Web Programming
Introduction to Python and Web ProgrammingDavid Neiss
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methodsPranavSB
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsagniklal
 
2015 bioinformatics python_io_wim_vancriekinge
2015 bioinformatics python_io_wim_vancriekinge2015 bioinformatics python_io_wim_vancriekinge
2015 bioinformatics python_io_wim_vancriekingeProf. Wim Van Criekinge
 
Bucc Toy Project: Learn programming through Game Development
Bucc  Toy Project: Learn programming through Game DevelopmentBucc  Toy Project: Learn programming through Game Development
Bucc Toy Project: Learn programming through Game DevelopmentSadaf Noor
 
Sustainable TDD
Sustainable TDDSustainable TDD
Sustainable TDDSteven Mak
 
Everything is Permitted: Extending Built-ins
Everything is Permitted: Extending Built-insEverything is Permitted: Extending Built-ins
Everything is Permitted: Extending Built-insAndrew Dupont
 
OpenFest 2012 : Leveraging the public internet
OpenFest 2012 : Leveraging the public internetOpenFest 2012 : Leveraging the public internet
OpenFest 2012 : Leveraging the public internettkisason
 

Similar a Teach your kids how to program with Python and the Raspberry Pi (20)

Python_book.pdf
Python_book.pdfPython_book.pdf
Python_book.pdf
 
Python
PythonPython
Python
 
Python
PythonPython
Python
 
Python
PythonPython
Python
 
Java for beginners
Java for beginnersJava for beginners
Java for beginners
 
Intro
IntroIntro
Intro
 
Scalable JavaScript
Scalable JavaScriptScalable JavaScript
Scalable JavaScript
 
Introduction to Python and Web Programming
Introduction to Python and Web ProgrammingIntroduction to Python and Web Programming
Introduction to Python and Web Programming
 
Unit-4 PPTs.pptx
Unit-4 PPTs.pptxUnit-4 PPTs.pptx
Unit-4 PPTs.pptx
 
Functions, List and String methods
Functions, List and String methodsFunctions, List and String methods
Functions, List and String methods
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
 
2015 bioinformatics python_io_wim_vancriekinge
2015 bioinformatics python_io_wim_vancriekinge2015 bioinformatics python_io_wim_vancriekinge
2015 bioinformatics python_io_wim_vancriekinge
 
Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
 
Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
 
Bucc Toy Project: Learn programming through Game Development
Bucc  Toy Project: Learn programming through Game DevelopmentBucc  Toy Project: Learn programming through Game Development
Bucc Toy Project: Learn programming through Game Development
 
Fuzzing - Part 1
Fuzzing - Part 1Fuzzing - Part 1
Fuzzing - Part 1
 
Sustainable TDD
Sustainable TDDSustainable TDD
Sustainable TDD
 
Everything is Permitted: Extending Built-ins
Everything is Permitted: Extending Built-insEverything is Permitted: Extending Built-ins
Everything is Permitted: Extending Built-ins
 
OpenFest 2012 : Leveraging the public internet
OpenFest 2012 : Leveraging the public internetOpenFest 2012 : Leveraging the public internet
OpenFest 2012 : Leveraging the public internet
 

Más de Juan Gomez

App Indexing: Blurring the Lines Between Your Website and App
App Indexing: Blurring the Lines Between Your Website and AppApp Indexing: Blurring the Lines Between Your Website and App
App Indexing: Blurring the Lines Between Your Website and AppJuan Gomez
 
REST is not enough: Using Push Notifications to better support your mobile cl...
REST is not enough: Using Push Notifications to better support your mobile cl...REST is not enough: Using Push Notifications to better support your mobile cl...
REST is not enough: Using Push Notifications to better support your mobile cl...Juan Gomez
 
Beating Android Fragmentation
Beating Android FragmentationBeating Android Fragmentation
Beating Android FragmentationJuan Gomez
 
Effective Android Messaging
Effective Android MessagingEffective Android Messaging
Effective Android MessagingJuan Gomez
 
Android Scripting
Android ScriptingAndroid Scripting
Android ScriptingJuan Gomez
 
Gae icc fall2011
Gae icc fall2011Gae icc fall2011
Gae icc fall2011Juan Gomez
 

Más de Juan Gomez (6)

App Indexing: Blurring the Lines Between Your Website and App
App Indexing: Blurring the Lines Between Your Website and AppApp Indexing: Blurring the Lines Between Your Website and App
App Indexing: Blurring the Lines Between Your Website and App
 
REST is not enough: Using Push Notifications to better support your mobile cl...
REST is not enough: Using Push Notifications to better support your mobile cl...REST is not enough: Using Push Notifications to better support your mobile cl...
REST is not enough: Using Push Notifications to better support your mobile cl...
 
Beating Android Fragmentation
Beating Android FragmentationBeating Android Fragmentation
Beating Android Fragmentation
 
Effective Android Messaging
Effective Android MessagingEffective Android Messaging
Effective Android Messaging
 
Android Scripting
Android ScriptingAndroid Scripting
Android Scripting
 
Gae icc fall2011
Gae icc fall2011Gae icc fall2011
Gae icc fall2011
 

Último

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Último (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Teach your kids how to program with Python and the Raspberry Pi

  • 2. Teach your kids how to program with Python and the Raspberry Pi Juan Gomez Co-Founder of PyhtonKC Twitter: @_juandg Saturday, May 4, 13
  • 3. May the 4th be with you! Saturday, May 4, 13
  • 4. So what is this talk really about? Saturday, May 4, 13
  • 5. Brief History of the RaspberryPi More at: https://www.youtube.com/watch?v=z-j4USHTLWM Saturday, May 4, 13
  • 7. What you’ll need: • MicroUSB Power Supply • SD Card (>= 4GB) • USB Keyboard • USB Mouse • Ethernet Cable • HDMI Cable • Monitor • Case? • HDMI to VGA Adapter? • USB WiFi Adapter? • USB to TTL Cable? • RCA Cable? Saturday, May 4, 13
  • 8. How do you teach kids? Saturday, May 4, 13
  • 10. Some tips • Seriously, Make it fun! • Start with Math • Be Patient • Explain the Basics • Use real life examples • Kids are slow typists! Saturday, May 4, 13
  • 11. How do I set it up? Saturday, May 4, 13
  • 13. Disclaimer • This an intro to Python for YOU, not your kids. • The kids version is at: https://github.com/ mechanicalgirl/young-coders-tutorial Saturday, May 4, 13
  • 14. A Python Code Sample x = 34 - 23 # A comment. y = “Hello” # Another one. z = 3.45 if z == 3.45 or y == “Hello”: x = x + 1 y = y + “ World” # String concat. print x print y Saturday, May 4, 13
  • 15. Enough to Understand the Code • First assignment to a variable creates it • Assignment is = and comparison is == • For numbers + - * / % are as expected • Special use: • + for string concatenation • % for string formatting (as in C’s printf) • Logical operators are words (and, or, not) not symbols (&&, ||, !). • The basic printing command is print Saturday, May 4, 13
  • 16. Comments • Start comments with #, rest of line is ignored • Can include a “documentation string” as the first line of a new function or class you define • Development environments, debugger, and other tools use it: it’s good style to include one def my_function(x, y): “““This is the docstring. This function does blah blah blah.””” # The code would go here... Saturday, May 4, 13
  • 17. Python and Types • Everything is an object! • “Dynamic Typing”-> • “Strong Typing” -> x = “the answer is ” y = 23 print x + y Saturday, May 4, 13 Data types determined automatically. Enforces them after it figures them out. # Decides x is string. # Decides y is integer. # Python will complain about this.
  • 18. Basic Datatypes • Integers (default for numbers) •z = 5 / 2 # Answer 2, integer division • Floats •x = 3.456 • Strings • Can use “” or ‘’ to specify with “abc” == ‘abc’ • Unmatched can occur within the string: “matt’s” • Use triple double-quotes for multi-line strings or strings that contain both ‘ and “ inside of them: “““a‘b“c””” Saturday, May 4, 13
  • 19. Whitespace Whitespace is meaningful in Python: especially indentation and placement of newlines •Use a newline to end a line of code Use when must go to next line prematurely •No braces {} to mark blocks of code, use consistent indentation instead • First line with less indentation is outside of the block • First line with more indentation starts a nested block •Colons start of a new block in many constructs, e.g. function definitions, then clauses Saturday, May 4, 13
  • 20. Assignment •You can assign to multiple names at the same time >>> x, y = 2, 3 >>> x 2 >>> y 3 This makes it easy to swap values >>> x, y = y, x •Assignments can be chained >>> a = b = x = 2 Saturday, May 4, 13
  • 21. A Python Code Sample x = 34 - 23 # A comment. y = “Hello” # Another one. z = 3.45 if z == 3.45 or y == “Hello”: x = x + 1 y = y + “ World” # String concat. print x print y Saturday, May 4, 13
  • 22. Side by Side with Java Java (C#) public class Employee { private String myEmployeeName; private int myTaxDeductions = 1; private String myMaritalStatus = "single"; Python class Employee(): def __init__(self, public Employee(String EmployeName) { this(EmployeName, 1); } employeeName public Employee(String EmployeName, int taxDeductions) { this(EmployeName, taxDeductions, "single"); } public Employee(String EmployeName, int taxDeductions, String maritalStatus) { this.myEmployeeName = EmployeName; this.myTaxDeductions = taxDeductions; this.myMaritalStatus = maritalStatus; } ): } Saturday, May 4, 13 , taxDeductions=1 , maritalStatus="single" self.employeeName = employeeName self.taxDeductions = taxDeductions self.maritalStatus = maritalStatus
  • 23. Life is Short (You Need Python) - Bruce Eckel (Thinking in C++) Saturday, May 4, 13
  • 24. Useful books: Python for Kids http://oreil.ly/10boyUq The Quick Python Book, 2nd Ed http://amzn.to/lXKzH5 Google's Python Class https://developers.google.com/edu/python/ Saturday, May 4, 13
  • 25. Let’s start by writing text based games Saturday, May 4, 13
  • 27. A Skeleton • Let’s start with the most basic pygame program template.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 from pygame import * from pygame.sprite import * from random import * init() screen = display.set_mode((640, 480)) display.set_caption('Window name!') while True: e = event.poll() if e.type == QUIT: quit() break Saturday, May 4, 13 screen.fill(Color("white")) display.update()
  • 28. Surface • Most of the game elements you see are represented as Surface • display.set_mode((x, y)) creates your canvas – it returns a Surface object Useful surface methods: • fill("color") fills the surface object it's been called from • blit(surface, area) paints the source surface onto the rectangle bounded by the area tuple – Example: screen.blit(ball, (50,50)) Saturday, May 4, 13
  • 29. Rect • Objects that store rectangular coordinates • Call .get_rect()on a surface to get its bounding box Rectangle methods/variables: • .center holds the object's center as a tuple • .colliderect(target) returns True if the parameter overlaps with the object • .collidepoint(target) returns True if the target point overlaps with the object Saturday, May 4, 13
  • 30. Media • Loading an image: – img = image.load("file.gif").convert() • Getting a bounding rectangle: – img_rect = img.get_rect() • Loading and playing a sound file: – mixer.Sound("file.wav").play() Saturday, May 4, 13
  • 31. Sprite • Simple base class visible game objects inherit from. Ball.py 1 2 3 4 5 6 7 8 9 10 11 from pygame import * from pygame.sprite import * class Ball(Sprite): def __init__(self): Sprite.__init__(self) self.image = image.load("ball.png").convert() self.rect = self.image.get_rect() Saturday, May 4, 13 def update(self): self.rect.center = mouse.get_pos()
  • 32. Using Sprites • They're just objects: initialize them – ball = Ball() • Create a group of sprites in main – sprites = RenderPlain(sprite1, sprite2) • Groups know how to draw and update – sprites.update() – sprites.draw(surface) Saturday, May 4, 13
  • 33. Events • User input such as clicking, moving mouse or key presses • Add more branches to test the result of event.poll() • Events to test for: – QUIT – MOUSEBUTTONDOWN – JOYBUTTONDOWN • Testing for the letter ‘d’ being pressed using KEYDOWN if e.type == KEYDOWN: if e.key == K_d: … Saturday, May 4, 13
  • 34. Adding Text • f = font.Font(font, size) goes before your game loop – Example: f = font.Font(None, 25) – Usually, None is a good enough font! • text = Font.render(text, antialias, color) – Example: text = f.render("Hello!", True, Color("green")) – Returns a surface • Must be blit, just like any other surface – Example: screen.blit(t, (320, 0)) Saturday, May 4, 13
  • 35. Let’s dissect a game! Saturday, May 4, 13
  • 36. Join PythonKC -> http:// www.meetup.com/pythonkc/ Saturday, May 4, 13
  • 37. Thanks! Juan Gomez Co-Founder of PyhtonKC Twitter: @_juandg Saturday, May 4, 13