1 / 10

Introduction to Computer Science – Chapter 2

Introduction to Computer Science – Chapter 2. CSc 2010 Spring 2011 Marco Valero. Overview. Python Tutorial Scribbler movements Defining new commands Adding parameters to commands Saving new commands in modules Functions as building blocks. Python Tutorial. Command Prompt Hello World!

gunda
Download Presentation

Introduction to Computer Science – Chapter 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Computer Science – Chapter 2 CSc 2010 Spring 2011 Marco Valero

  2. Overview • Python Tutorial • Scribbler movements • Defining new commands • Adding parameters to commands • Saving new commands in modules • Functions as building blocks

  3. Python Tutorial • Command Prompt • Hello World! • Giving Commands • Functions • Parameters • Module • import os,sys • sys.path.append('/path/to/module')

  4. Movements • motor(LEFT, RIGHT) • LEFT, RIGHT = [-1.0, 1.0] • forward(SPEED) • SPEED = [-1.0,1.0] • backward(SPEED) • turnLeft(SPEED) • turnRight(SPEED) • stop()

  5. Movements • forward(SPEED, SECONDS) • SECONDS = [0.0, …] • backward(SPEED , SECONDS) • turnLeft(SPEED , SECONDS) • turnRight(SPEED , SECONDS)

  6. Defining new commands def yoyo(): forward(1) backward(1) stop() def yoyo(): forward(1, 1) backward(1,1)

  7. Defining new commands def yoyo(): forward(1) wait(1) backward(1) wait(1) stop()

  8. Adding parameters to commands def yoyo(speed, waitTime): forward(speed) wait(waitTime) backward(speed) wait(waitTime) stop() • speed, waitTime are our parameters

  9. Saving new commands in modules # File: moves.py # Purpose: Two useful robot commands to try out as a module. # First import myro and connect to the robot from myro import * init() # Define the new functions... def yoyo(speed, waitTime): forward(speed) wait(waitTime) backward(speed) wait(waitTime) stop() def wiggle(speed, waitTime): rotate(-speed) wait(waitTime) rotate(speed) wait(waitTime) stop()

  10. Functions as building blocks def dance(): yoyo(0.5,0.5) yoyo(0.5,0.5) wiggle(0.5,1) wiggle(0.5,1)

More Related