Python programming Introduction to the JES environment and basics of Python Reading: Chapters 1, 2 from “Introduction to Computing and Programming in Python”

Slides:



Advertisements
Similar presentations
Python: Modifying Pictures Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
Advertisements

Tutorial 12: Enhancing Excel with Visual Basic for Applications
© 2010 Delmar, Cengage Learning Chapter 9: Using ActionScript.
The Web Warrior Guide to Web Design Technologies
CS1315: Introduction to Media Computation Introduction to Programming.
Created by Mark Guzdial, Georgia Institute of Technology; modified by Robert H. Sloan, University of Illinois at Chicago, For Educational Use. CS.
Media Computation in JES (Chapter 2) DM Rasanjalee Himali.
Python: Making colors and Using Loops. Review JES command area – program area Defining/using functions specifying a sequence of steps for what the function.
Chapter 2: Introduction to Programming. Chapter Learning Objectives.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
Python. What is Python? A programming language we can use to communicate with the computer and solve problems We give the computer instructions that it.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Graphics in Python using the JES environment
Python.
Visual Basic Chapter 1 Mr. Wangler.
Python Programming Fundamentals
CS 102 Computers In Context (Multimedia)‏ 01 / 28 / 2009 Instructor: Michael Eckmann.
Adding Content To Your Faculty Page 1.Login 2.Create your Faculty Page 3.
CS 101: Introduction to Computing Programming picture manipulations Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Download JES Tool JES: Jython Environment for Students
Lecture # 27 Python I. Python “Interpretive” language (vs. compiled) So is HTML, JavaScript. Python supports file I/O. JavaScript doesn’t Python is a.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Microsoft Office Excel Copyright © 2008 Pearson Prentice Hall. All rights reserved
First Program  Open a file  In Shell  Type into the file: 3  You did it!!! You wrote your first instruction, or code, in python!
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Lesson 1 Introduction.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
CMPS 1371 Introduction to Computing for Engineers MatLab.
CS1315: Introduction to Media Computation Introduction to Programming.
CS 102 Computers In Context (Multimedia)‏ 01 / 26 / 2009 Instructor: Michael Eckmann.
Introduction to Programming with RAPTOR
CS 100 Introduction to Computing Introduction to JES Developed by Mark Guzdial, Georgia Institute of Technology, 2003–2004; modified by Robert H. Sloan.
A Simple Quiz: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009, added Part 2 July 2011.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
A Media Computation Cookbook Manipulating Images and Sounds for Use in Alice Part 1: Image Manipulations Part 2: Changing colors in an area Part 3: Chromakey.
1 CS 177 Week 2 Recitation Slides Variables, Files and Functions.
CS1315: Introduction to Media Computation Introduction to JES.
Python programming Introduction to the JES environment and basics of Python.
CS1315: Introduction to Media Computation Introduction to Programming.
Python programming Using the JES picture functions and defining new functions.
First Program  Open a file  In Shell  Type into the file: 3  You did it!!! You wrote your first instruction, or code, in python!
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
CS1315: Introduction to Media Computation Introduction to JES.
 Prepared by: Eng. Maryam Adel Abdel-Hady
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Using Macros Lesson.
Part 1 Learning Objectives To understand that variables are a temporary named location to store data and that programmers work with different data types.
PROBLEM SOLVING WARM-UP Fill in the spaces using any operation to solve the following (!, (), -/+,÷,×): = 6.
Multimedia Summer Camp
Development Environment
A Playful Introduction to Programming by Jason R. Briggs
Introduction to Programming
Introduction to Python
Introduction to the JES environment and basics of Python
CS1315: Introduction to Media Computation
Chapter 2: Introduction to Programming
Chapter 2: Introduction to Programming
Introduction to TouchDevelop
A Media Computation Cookbook
Workshop for Programming And Systems Management Teachers
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Variables & getting info from the user
CS 177 Week 3 Recitation Slides
Presentation transcript:

Python programming Introduction to the JES environment and basics of Python Reading: Chapters 1, 2 from “Introduction to Computing and Programming in Python”

Python The programming language we will be using is called Python – –It’s used by companies like Google, Industrial Light & Magic, Nextel, and others The kind of Python we’re using is called Jython –It’s Java-based Python – We’ll be using a specific tool to make Python programming easier, called JES (Jython Environment for Students).

JES - Jython Environment for Students Program area - A simple editor for programs Command area - Interaction with Jython

>>> >>> ‘spam’ ‘spam’ >>> “spam” ‘spam’ >>> “spam and more spam” ‘spam and more spam’ >>> ‘spam’ + ‘spam’ ‘spamspam’ Python interaction through commands Anything you type in command area is evaluated and its value is displayed Example: prompt

>>> print >>> print ‘spam’ spam >>> ‘spam’ + ‘spam’ ‘spamspam’ >>> print ‘spam’ + ‘spam’ Spamspam print displays the value of an expression In many cases it makes no difference whether you use print - the result gets displayed anyway. Note: no quotes!

Command Area Editing Up/down arrows walk through command history You can edit the line at the bottom –Just put the cursor at the end of the line before hitting Return/Enter.

Variables are names for data Example: a= 3 b= -1 c = 2 x = 0 f = a*x*x + b*x + c

Variables -more examples Variables of other types newsItem = “You’ve got spam!” Variables keep their value for the duration of a program or until they get a new value through a new assignment a = 3 b = a *2 + 5 a = 0 Up to this point the value of a is still 3, but then it changes to 0

Python functions Python has a lot of built-in functions for general mathematical manipulation, eg: sqrt(4) - computes the square root of 4 ord(‘A’) - computes the ASCII code for character ‘A’ Example: print (-b+sqrt(b*b - 4*a*c))/2*a

But what exactly is a function? F(a,b) 4 ‘a’F(4, ‘a’) side-effects

Functions in general F(a,b) 4 ‘a’F(4, ‘a’) side-effects

Example: sqrt() sqrt(a) 4 2 side-effects

JES Functions A bunch of functions are pre-defined in JES for sound and picture manipulations –pickAFile() –makePicture() –makeSound() –show() –play() Some of these functions accept input values theFile = pickAFile() pic = makePicture(theFile)

Example: pickAFile() pickAFile() Filename (eg: C:\Documents and Settings\mpapalas\My Documents\greenroom.jpg) Pops up a dialog box for the user to select a file

Picture Functions makePicture(filename) creates and returns a picture object, from the JPEG file at the filename show(picture) displays a picture in a window We’ll learn functions for manipulating pictures later, like getColor(), setColor(), and repaint()

Example: makePicture() makePicture(filename) Picture object corresponding to image that is saved in theFile theFile makePicture(filename) creates and returns a picture object, from the JPEG file at the filename

Example: show() show(picture-obj) Picture object corresponding to image that is saved in theFile Pops up a new window displaying image stored in the the picture object

Demonstrating picture manipulation with JES >>> >>> print pickAFile() C:\Documents and Settings\mpapalas\Desktop\sample.jpg >>> theFile = "C:\Documents and Settings\mpapalas\Desktop\sample.jpg" >>> makePicture(theFile) Picture, filename C:\Documents and Settings\mpapalas\Desktop\sample.jpg height 1200 width 1600 >>> print makePicture(theFile) Picture, filename C:\Documents and Settings\mpapalas\Desktop\sample.jpg height 1200 width 1600 >>> pic = makePicture(theFile) >>> print pic Picture, filename C:\Documents and Settings\mpapalas\Desktop\sample.jpg height 1200 width 1600 >>> show(pic)

Writing a recipe: Making our own functions def fcnName (input1, input2,...) : block describing what the function should do return value To make a function, use the command def Then, the name of the function, and the names of the input values between parentheses (“(input1)”) Important: End the line with a colon (“:”) The body of the recipe is indented (Hint: Use two spaces) –That’s called a block –Optionally, the function can return a value

Writing a recipe: Making our own functions def fcnName (input1, input2,...) : block describing what the function should do return value To make a function, use the command def Then, the name of the function, and the names of the input values between parentheses (“(input1)”) Important: End the line with a colon (“:”) The body of the recipe is indented (Hint: Use two spaces) –That’s called a block –Optionally, the function can return a value Optional

pickAFile() Pops up a dialog box for the user to select a file theFile A recipe for displaying picked picture files def pickAndShow(): theFile = pickAFile() Defines a new function

pickAFile() Pops up a dialog box for the user to select a file makePicture(filename) pic theFile A recipe for displaying picked picture files def pickAndShow(): theFile = pickAFile() pic = makePicture(theFile)

pickAFile() Pops up a dialog box for the user to select a file makePicture(filename) pic theFile show(picture-obj) Pops up a new window displaying image stored in the the picture object A recipe for displaying picked picture files def pickAndShow(): theFile = pickAFile() pic = makePicture(theFile) show(pic)

pickAFile() Pops up a dialog box for the user to select a file makePicture(filename) pic theFile show(picture-obj) Pops up a new window displaying image stored in the the picture object A recipe for displaying picked picture files def pickAndShow(): theFile = pickAFile() pic = makePicture(theFile) show(pic) pickAndShow()

A recipe for playing picked sound files def pickAndPlay(): myfile = pickAFile() mysound = makeSound(myfile) play(mysound) Note: myfile and mysound, inside pickAndPlay(), are completely different from the same names in the command area.

Anything complicated is best done in the Program Area Program area - A simple editor for programs Command area - Interaction with Jython

Using the Program Area Type your program (or cut and paste from the command area) Save (or Save As) - use.py for file extension Load Program (click on button between command and program areas) –Before you load it, the program is just a bunch of characters. –Loading encodes it as an executable function –You must Save before Loading –You must Load before you can use your function

Making functions the easy way Get something working by typing commands Enter the def command. Copy-paste the right commands up into the recipe

Names for variables and functions can be (nearly) anything! Must start with a letter (but can contain numerals) Can’t contain spaces –myPicture is okay but my Picture is not Be careful not to use command names as your own names –print = 1 won’t work –(Avoid names that appear in the editor pane of JES highlighted in blue or purple) Case matters –MyPicture is not the same as myPicture or mypicture Sensible names are sensible –E.g. myPicture is a good name for a picture, but not for a picture file. –x could be a good name for an x-coordinate in a picture, but probably not for anything else

Blocking is indicated for you in JES Statements that are indented the same, are in the same block. Statements that are in the same block as where the line where the cursor is are enclosed in a blue box.

Now what? When you load your program, what happens with the function? After a program with a function definition is loaded, that function can be used either from the command or the program area Try using your function by typing pickAndShow() in the command area

Exploring more functions The JES Functions menu has functions arranged by type - check them out! Can you find a function that inputs a number? Can you find under what category pickAFile() is listed?

Reading Chapters 1, 2 from “Introduction to Computing and Programming in Python”

Assignment Create a function that… –Causes an interactive input window to pop up and request some form of input from the user and stores it in a variable –Displays the value stored in the variable –Displays an image from a file Save your function in a file Load it Use the function in the command area to make sure that it works and does what you want it to do Submit your file through webct