Function in Notepad def drawSquare(myTurtle): myTurtle.forward(100) myTurtle.right(90) # side 1 myTurtle.forward(100) myTurtle.right(90) # side 2 myTurtle.forward(100)

Slides:



Advertisements
Similar presentations
COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
Advertisements

CS 100: Roadmap to Computing Fall 2014 Lecture 02: Fun With Turtles.
CS1315: Introduction to Media Computation Making sense of functions.
Noadswood Science,  To know how to use Python to produce windows and colours along with specified co-ordinates Sunday, April 12, 2015.
By Now, 1. Your Student ID should open the classroom door 2. You should have C:\100 folder Desktop shortcuts to Command Prompt and Notepad 3. You should.
Computer Science 1000 LOGO I. LOGO a computer programming language, typically used for education an old language (1967) the basics are simple: move a.
How do we make our Welcome.java program do something? The java in our Welcome.java file won’t do anything by itself. We need to tell the computer to execute.
Programming Introduction November 9 Unit 7. What is Programming? Besides being a huge industry? Programming is the process used to write computer programs.
B.A. (Mahayana Studies) Introduction to Computer Science November March Logo (Part 1) An introduction to Logo: drawing, moving,
Python plotting for lab folk Only the stuff you need to know to make publishable figures of your data. For all else: ask Sourish.
PYTHON: LESSON 1 Catherine and Annie. WHAT IS PYTHON ANYWAY?  Python is a programming language.  But what’s a programming language?  It’s a language.
Streaming Twitter. Install pycurl library Use a lab computer From the course website Download the links from pycurl and twitter streamer Extract site-packages.zip,
Introduction to Programming Writing Java Beginning Java Programs.
PYTHON CONDITIONALS AND RECURSION : CHAPTER 5 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
Computer Science 111 Fundamentals of Programming I Introduction to Graphics.
Lesson 2 Solid Works GUI and the Design Process. Model Parts Set Up Document Properties –Select a Plane Create a 2D Sketch Create a 3D Feature.
Fill in the blanks: (1) ______tool is used for selection in paint program. (2) _____tool makes the letter bold. (3) In paint program ________ tool is used.
You SHOUD HAVE.. C:\100 folder A desktop shortcut to “IDLE (Python34)”
Class 2 Introduction to turtle graphics
Turtle see, turtle do Lesson 1 – Welcome to LOGO.
Writing Methods Mrs. C. Furman October 9, Drawing a Square World worldObj = new World(); Turtle turtle1 = new Turtle(100, 100, worldObj); turtle1.forward.
Unit 1, Lesson 3 Program Execution Process AOIT Introduction to Programming Copyright © 2009–2012 National Academy Foundation. All rights reserved.
Chapter 1. Objectives To provide examples of computer science in the real world To provide an overview of common problem- solving strategies To introduce.
Function Abstraction Black Box Container for a sequence of actions Call, execute, invoke the function by name Good for abstraction of key operations Good.
CS1315: Introduction to Media Computation Making sense of functions.
CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan.
CONTROL SYSTEMS Control Systems A command is a directive that performs a specific task An argument is a variable that can be used by the function reveiving.
Lorenzo and Tyra’s Wedding November 5, 2009 Burj Al Arab Hotel Dubai, United Arab Emirates.
Introduction to Programming Writing Java Beginning Java Programs.
Processing Workshop. What is processing? “Processing is an open source programming language and environment for people who want to program images, animation,
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 4: Writing programs.
You Need an Interpreter!. Closing the GAP Thus far, we’ve been struggling to speak to computers in “their” language, maybe its time we spoke to them in.
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
CS1315: Introduction to Media Computation Introduction to JES.
Click left mouse button to proceed. Windows Tutorial Searching For Files CST-133 Lab AW © Delta College CST Faculty.
Let’s Learn 3. Modules Saenthong School, January – February 2016
Turtle Graphics Let’s see what we can draw on Python!
An urn contains 1 green, 2 red, and 3 blue marbles. Draw two without replacement. 1/6 2/6 3/6 2/5 3/5 1/5 3/5 1/5 2/5 2/30 3/30 2/30 6/30 3/30 6/30.
Turtle Graphics Lesson 2 1. There are 3 homeworks to complete during the six lessons of this unit. Your teacher will let you know when a homework has.
3 rd grade Math Practice Thinking Problems. Solve the problems in class. Bring the finished packet to the computer lab. In the computer lab you will use.
LOGO WHAT IS IT? HOW TO USE IT AND HOW USEFUL CAN IT BE?
CS1315: Introduction to Media Computation Making sense of functions.
Using the Python Turtle
Multimedia Summer Camp
Computer Programming.
Python’s Modules Noah Black.
For vs. While loop count=0 while count< 5: for count in range(5):
Introduction to Programming
How to change the LOGO on PecStarWeb V3.6
While loop Get names up to five times count=0 while count< 5:
Introduction to Python
What you asked me to teach…
Do it now activity Last lesson we used Flowol to create a solution to a problem a computer could solve. Identify what each symbol does:
turtle module Simple graphics programming How to use it ?
CS 100: Roadmap to Computing
Algorithms and Flow Charts
البرمجة مع لغة PYTHON TURTLE
CS 100: Roadmap to Computing
Fractions 1/2 1/8 1/3 6/8 3/4.
Computer Vocabulary Desktop
Chap. 3 Functions Start Python IDLE (Shell) and open a new file.
Finish Explorer Cards Discard Pile
Test123 blah. hjghgghhg.
Python Lesson’S 1 & 2 Mr. Kalmes.
Scripts In Matlab.
Python Modules.
Lab 2: Terminal Basics.
Defining Functions.
Presentation transcript:

Function in Notepad def drawSquare(myTurtle): myTurtle.forward(100) myTurtle.right(90) # side 1 myTurtle.forward(100) myTurtle.right(90) # side 2 myTurtle.forward(100) myTurtle.right(90) # side 3 myTurtle.forward(100) myTurtle.right(90) # side 4

Saved Function in C:\ Open a Notepad, and enter function statements 2. Save the file with.py extension Save it as drawS.py in C:\ Open a Command Window “cd../../100” to bring the system to C:\100 folder “python” “>>> import turtle” “>>> myT = turtle.Turtle()” “>>> import drawS” “>>> drawS.drawSquare(myT, 100)”

Questions File name is drawS.py  But why use drawS.drawSquare()  Bring Python to C:\100 folder where drawS.py is  Import drawS  Within drawS.py, execute drawSqure() function drawS.py has ‘myTurtle’ But why use drawS.drawSquare(myT) def drawSquare(myTurtle): myTurtle.forward() myTurtle.right(90) … drawS.py

Arguments are placeholders Think of an argument as a placeholder  It takes the place of the actual input object Only when a function is executed, the input object takes actual values replacing the argument def drawSquare(myTurtle): myTurtle.forward(100) myTurtle.right(90) … >>> myT=turtle.Turtle() >>> myT.forward(100) >>> myT.right(90) >>> myT…. >>> myT=turtle.Turtle() >>> drawS.drawSquare(myT) =

What if we want a function drawS() to draw a square of different sizes ? From To def drawSquare(myTurtle, sideLength): myTurtle.forward(sideLength) myTurtle.right(90) … def drawSquare(myTurtle): myTurtle.forward(100) myTurtle.right(90) …

An imaginary wedding computer def marry(husband, wife): sayVows(husband) sayVows(wife) pronounce(husband, wife) kiss(husband, wife) def sayVows(speaker): print “I, “ + speaker + “ blah blah” def pronounce(man, woman): print “I now pronounce you…” def kiss(p1, p2): if p1 == p2: print “narcissism!” if p1 <> p2: print p1 + “ kisses “ + p2 So, how do we marry Ben and Jo ?

An imaginary wedding computer def marry(husband, wife): sayVows(husband) sayVows(wife) pronounce(husband, wife) kiss(husband, wife) def sayVows(speaker): print “I, “ + speaker + “ blah blah” def pronounce(man, woman): print “I now pronounce you…” def kiss(p1, p2): if p1 == p2: print “narcissism!” if p1 <> p2: print p1 + “ kisses “ + p2

An imaginary wedding computer def marry(husband, wife): sayVows(husband) sayVows(wife) pronounce(husband, wife) kiss(husband, wife) def sayVows(speaker): print “I, “ + speaker + “ blah blah” def pronounce(man, woman): print “I now pronounce you…” def kiss(p1, p2): if p1 == p2: print “narcissism!” if p1 <> p2: print p1 + “ kisses “ + p2

>>> import turtle >>> tt = turtle.Turtle() >>> tt.width(5) >>> tt.color(“blue”) >>> tt.circle(100) >>> tt.up() >>> tt.goto(150,0) >>> tt.down() >>> tt.color(“black“) >>> tt.circle(100) >>> tt.up() >>> tt.goto(300,0) >>> tt.down() >>> tt.color(“red“) ….. LAB: Can we make a function for Olympic rings?