Top Banner

of 23

2010 04 24 PSCSTA Scribblers

May 30, 2018

Download

Documents

Hélène Martin
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    1/23

    Python and

    Scribbler Robots

    Hlne Martin

    Puget Sound CSTA

    April 24th, 2010

    Special thanks to Marty Stepp for some formatting and contentFriday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    2/23

    Hlne Martin

    Bachelors in CS from UW

    Career and Technical Ed through South Seattle

    Teach at comprehensive public high school

    Five periods of computer science

    - 2x Exploring Computer Science- 2x Creative Computing- 1x AP Computer Science

    http://garfieldcs.com

    Friday, April 23, 2010

    http://garfieldcs.com/http://garfieldcs.com/http://garfieldcs.com/
  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    3/23

    Game Plan

    Why bother with Python

    Python language basics

    Why bother with Scribblers

    myro package basics

    Play!

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    4/23

    Why Teach Python?

    Light-weight syntax

    Scalable (small hacks to GUI apps)

    Lots of great libraries- myro (today)- pygame- scipy

    InterpretedPermissive

    Used increasingly in college courses

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    5/23

    Why Not Teach Python?

    Permissive

    Dynamically typed (values have types, but not

    variables)

    Too many ways to skin a single cat!

    Not used much in corporate world

    - Though YouTube, Google, Yahoo!, NASA make some use of it

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    6/23

    Getting Python

    Free at http://python.org

    Generally pre-installed on OS X or Linux

    Includes Idle, an IDE

    Friday, April 23, 2010

    http://python.org/http://python.org/
  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    7/23

    Interacting With Python

    Programs saved with .py extensions

    Commands interpreted straight in shell

    Students can get confused about the two!!

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    8/23

    Print Function

    Simple! (no System.out.yuck)

    Can be called with parameters of different types

    Concatenation shows ugliness of dynamic types

    Print can dis la different t es

    1

    2

    3

    4

    print("Hello, world!")

    print()

    print(25)

    print("You have " + str(dollars) + " dollars")

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    9/23

    Python Operations

    Arithmetic:

    - ** (exponent)- * (multiplication) / (division) % (modulus)- + (addition) - (subtraction)

    Boolean

    - == != < >=- not

    - and or

    Common Types

    - int, float, bool, str

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    10/23

    White Space

    Indentation indicates blocks

    Super offensive at first glance, but one gets over it

    - its NOT like shell scripting!

    Colon indicates containers, everything indented

    under is governed by that container

    In entation matters

    1

    2

    3

    4

    for i in range(3):print("Hello") # repeatedprint(25) # repeated

    print("Hi") # not repeated

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    11/23

    Iteration

    Definite loop

    Indefinite loop

    Ba ic for loop structure

    1

    2

    3

    4

    for i in range():

    print("Hi") # not repeated

    While loop strcture

    1

    2

    3

    4

    while():

    print("Hi") # not repeated

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    12/23

    Conditionals

    Co ditional structure

    1

    2

    3

    4

    5

    6

    if(): elif():

    else:

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    13/23

    Functions

    Definition

    Calling

    - A common error is to forget parentheses after the call

    The def ke word is used for definin functions

    1

    23

    4

    5

    def hello(, ):

    print("Hello, world!)

    hello()hello()

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    14/23

    External Libraries

    Import modules to get access to more functions

    Usi random numbers

    12

    3

    4

    from random import *

    die1 = randint(1, 6)die2 = randint(1, 6)

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    15/23

    Python Resources

    http://python.org/

    http://diveintopython.org

    http://openbookproject.net//thinkCSpy/

    Friday, April 23, 2010

    http://openbookproject.net//thinkCSpy/http://openbookproject.net//thinkCSpy/http://diveintopython.org/http://diveintopython.org/http://python.org/http://python.org/
  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    16/23

    Scribblers

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    17/23

    Why Teach With Scribblers

    Visual and tactile feedback is motivating

    Opportunity to discuss robotics

    Cool factor

    Indestructible and no assembly necessary

    Uses a real language

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    18/23

    Why Not Teach With Scribblers

    Flakiness leads to frustration

    Too many things going on

    Limited interesting applications

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    19/23

    My Successes

    Python as primary language in Creative

    Computing

    - 120 students so far

    2 week unit on Scribblers for Creative

    - Students already know a lot of Python

    Great projects: object detection, piano,

    obstacle course completion

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    20/23

    My Challenges

    Python as quick introduction to real language

    after Scratch in Exploring Computer Science

    1 week intro to Scribblers for ExploringEnded unit early because students just werent

    getting it and flakiness was irritating!

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    21/23

    myro

    Python library gives access to Scribbler functions

    Co e needed to et oin with m ro

    12

    from myro import *init()

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    22/23

    A Sample Program

    def flashLight(times):for i in range(times):

    setLED("back",1)wait(0.55)setLED("back",0)wait(0.25)

    def senseLoop():# getLight() is a function that gives back three values# Here we save them in three variables.rightSensor, centerSensor, leftSensor = getLight()

    # Print out all three sensor valuesprint "Light Sensor Values:", rightSensor, centerSensor, leftSensor;

    # If the right sensor is coveredif rightSensor > 2000:

    # You can write a song using note names and beat lengthsplaySong(makeSong("c 1; g 1/4; a 1/2; e 3/4;") )# Make the back LED flashflashLight(5)

    if centerSensor > 5000:print "BAGELS BAGELS GGRRAA" # don't ask; it's latewait(0.25)beep(0.25,440,880)

    if leftSensor > 2000:turnLeft(1,0.5)

    # Continue sensing for 20 secondswhile(timeRemaining(20)):

    senseLoop()

    Friday, April 23, 2010

  • 8/9/2019 2010 04 24 PSCSTA Scribblers

    23/23

    Play Time!