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.

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

Lecture 04 – Classes.  Python has a number of classes built-in  lists, dictionaries, sets, int, float, boolean, strings  We can define our own classes.
Python Basics: Statements Expressions Loops Strings Functions.
CS1315: Introduction to Media Computation Making sense of functions.
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)
Surrey Libraries Computer Learning Centres Totally New to Computers Computer Basics March 2013 Teaching Script.
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.
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.
Python Programming Fundamentals
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,
Algorithms Algorithms are a familiar idea. Our goal is to learn to specify them right so someone or something else does the work.
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
COMP 171: Functions, for loops and range John Barr Section 03 Slides by Toby Dragon.
Shell Scripting Introduction. Agenda What is Shell Scripting? Why use Shell Scripting? Writing and Running a Shell Script Basic Commands -ECHO - REM.
Functions and subroutines – Computer and Programming.
HTML, XHTML, and CSS Chapter 8 Adding Multimedia Content to Web Pages.
Introduction to: Python and OpenSesame Part I. Python A high-level programming language It can do a lot of things We will use python in this course in.
Oct 15, 2007Sprenkle - CS1111 Objectives Creating your own functions.
You SHOUD HAVE.. C:\100 folder A desktop shortcut to “IDLE (Python34)”
Class 2 Introduction to turtle graphics
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 12: A few other things.
Writing Methods Mrs. C. Furman October 9, Drawing a Square World worldObj = new World(); Turtle turtle1 = new Turtle(100, 100, worldObj); turtle1.forward.
Chapter 1. Objectives To provide examples of computer science in the real world To provide an overview of common problem- solving strategies To introduce.
Make a blank window This is a starter activity and should take 5 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.In script mode create a file.
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.
Overview of Microsoft Access. Contents of an Access file Tables Forms Queries Reports Pages Macros Modules.
THINKING BIG Abstraction and Functions chapter 6 Modified by Dr. Paul Mullins for CPSC 130, F05.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
COM S 207 Method Instructor: Ying Cai Department of Computer Science Iowa State University
Programming for GCSE 1.0 Beginning with Python T eaching L ondon C omputing Margaret Derrington KCL Easter 2014.
IDLE An IDE for Python bundled with the program release Click on IDLE (Python GUI) in the Start menu under the Python program group  Get the IDLE Python.
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.
Introduction to Matlab Module #10 Page 1 Introduction to Matlab Module #10 – Creating Graphical User Interfaces Topics 1.Overview of GUI Development using.
Click left mouse button to proceed. Windows Tutorial Searching For Files CST-133 Lab AW © Delta College CST Faculty.
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
Extending MATLAB Write your own scripts and/or functions Scripts and functions are plain text files with extension.m (m-files) To execute commands contained.
Unix Fundamentals CS 127. File navigation cd - change directory cd /var/log cd /etc/apache2 cd ~/Desktop ~ is a shortcut for the home directory.
BUILDING A WEB PAGE BASIC HTML CODING. We first open notepad to start to build our web page. We enter the code at the beginning. And then we write below.
Turtle Graphics Let’s see what we can draw on Python!
CS1315: Introduction to Media Computation Making sense of functions.
CSC 1010 Programming for All Lecture 5 Functions Some material based on material from Marty Stepp, Instructor, University of Washington.
Multimedia Summer Camp
A little PHP.
Computer Programming.
Python’s Modules Noah Black.
Python Lesson 12 Mr. Kalmes.
Introduction to Programming
Topics Introduction to Repetition Structures
Basic operations in Matlab
Python Lesson 12 Mr. Kalmes.
Python Mr. Husch.
Integrating JavaScript and HTML
Computer Vocabulary Desktop
Introduction to Programming
How to PostPower Point Presentations
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Python Lesson’S 1 & 2 Mr. Kalmes.
Scripts In Matlab.
Test Automation For Web-Based Applications
Python Modules.
General Computer Science for Engineers CISC 106 Lecture 03
Introduction to Programming
The Python interpreter
Functions Overview © 2018 Kris Jordan.
Defining Functions.
Presentation transcript:

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 know Class webpage: How to create a turtle How to move it and change properties

Draw a Square >>> import turtle >>> myTurtle = turtle.Turtle() >>> 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

Simpler way of handling repetition ? => Functions Abstraction Black Box Container for a sequence of actions Use the function by name

Figure 1.8

Defining Functions Name Parameters Body

Listing 1.1 def functionName(param1,param2,...) : statement1 statement2...

Listing 1.2 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

Figure 1.10

How to Use a Function 1 1. Open a Notepad, and enter function statements 2. Save the file with.py extension Such a file is called a module, script, function Save it as drawS.py in C:\100

How to Use a Function 2 3. 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 we use ‘drawS.drawSquare() Parameter name is myTurtle But we 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) …

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