Peter Andreae Python Workshop for Teachers #2, 3.

Slides:



Advertisements
Similar presentations
Noadswood Science,  To know how to use Python to produce windows and colours along with specified co-ordinates Sunday, April 12, 2015.
Advertisements

Python, CGI November 23, Unit 8. So Far We can write programs in Python (in theory at least) –Conditionals –Variables –While loops We can create a form.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
Concatenation MATLAB lets you construct a new vector by concatenating other vectors: – A = [B C D... X Y Z] where the individual items in the brackets.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Python quick start guide
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Python Workshop CH4HS Dec 2012 see website: ecs.vuw.ac.nz/Main/PythonForSchools.
WEEK Introduction to GUI programming. Introduction Each data type can represent a certain set of values, and each had a set of associated operations.
Lists in Python.
Data Structures in Python By: Christopher Todd. Lists in Python A list is a group of comma-separated values between square brackets. A list is a group.
Python November 28, Unit 9+. Local and Global Variables There are two main types of variables in Python: local and global –The explanation of local and.
Peter Andreae Python for Level 3 CS4HS see website: ecs.vuw.ac.nz/Main/PythonForSchools.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Lists Computers and Programming. Agenda What is a list? How to access elements in the list? The for statement Operations on lists Looping with.
 Pearson Education, Inc. All rights reserved Arrays.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
PC204 Lecture 9 Conrad Huang Genentech Hall, N453A x
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
PYTHON GUI PROGRAMMING
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.
Python Programming Graphical User Interfaces Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Computing Science 1P Lecture 17: Friday 23 rd February Simon Gay Department of Computing Science University of Glasgow 2006/07.
Built-in Data Structures in Python An Introduction.
Reports and Queries Chapter 3 – Access text Reports – Page Queries – Page
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
Lists. The list is a most versatile datatype available in Python which can be written as a list of comma-separated values (items) between square brackets.
xy ? {(3,-2), (5,4), (-2,0)}. A relation is set of ordered pairs, where one number is mapped to another number.
Xiaoying Gao Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, Victoria University of Wellington More Interfaces.
Python Arrays. An array is a variable that stores a collection of things, like a list. For example a list of peoples names. We can access the different.
I Power Higher Computing Software Development Development Languages and Environments.
Graphical User Interface You will be used to using programs that have a graphical user interface (GUI). So far you have been writing programs that have.
1 CSC 221: Introduction to Programming Fall 2011 Lists  lists as sequences  list operations +, *, len, indexing, slicing, for-in, in  example: dice.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
If the same piece of code needs to be used several times we can use a loop – but only if those times are all together. If you need to run the same bit.
Creating visual interfaces in python
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.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington ArrayLists: varying size arrays.
Count Controlled Loops (Nested) Ain’t no sunshine when she’s gone …
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington ArrayLists: varying size arrays.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Arrays.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 9: Arrays; Revision Session.
Magic 8 ball. "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 10: Files.
ENGINEERING 1D04 Tutorial 4. What are we doing today? Focus Functions Scope of Variables Returning Values Objects Graphics library Aliasing Events Mouse.
Starter You have been asked to write a program to store the names of everybody in a class. Assuming there are 20 pupils in the class, how would you do.
Lexical Reference Variables in Graphics and List Box in Forms
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Miscellaneous Topics #6: Polygons GUI Components and Event Handlers
Tkinter GUIs Computer Science and Software Engineering
Let’s make a shape…. Move!
Python I/O.
CS190/295 Programming in Python for Life Sciences: Lecture 6
8 – Lists and tuples John R. Woodward.
Data Structures – 1D Lists
Intro to Computer Science CS1510 Dr. Sarah Diesburg
ARRAYS 1 GCSE COMPUTER SCIENCE.
Starter As the teacher is calling out the register think about what sort of program you would write to duplicate the process that the teacher has just.
MSIS 655 Advanced Business Applications Programming
Topics Graphical User Interfaces Using the tkinter Module
Arrays ICS2O.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
JavaScript: Arrays.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Tuple.
Presentation transcript:

Peter Andreae Python Workshop for Teachers #2, 3

© Peter Andreae Lists Lists are a collection of items in order Like arrays, but better can be extended or shortened can be acted on as a whole eg, can be stored in variable, passed to function, printed out, … can act on individual elements, indexed by position (0,1,2….) Written with square brackets, comma separated, eg names = ["peter", "james", "justine"] ages = [ ] Access using index in [ ]: print(names[2] ) names[i] = "unknown" Append to end: names.append("jillian")

© Peter Andreae Example Programs concordance: lists of words for item in list len(list), append, in, primes lists of numbers access and change elements function with parameters print with sep & and off-by-1 errors optimisation

© Peter Andreae To Do: stats: read a line of numbers into a list then find min, max, average list all numbers less than half the average. wordList read a list of words from user print out shortest and longest word any word starting with a vowel wordShifter: read a list of words repeatedly, ask user for index of a word to move to the left swap the word with its neighbour print out the line

© Peter Andreae Graphical output and GUI Need tkinter library to do any graphical input/output or GUI Simple graphical output: set up window and canvas call drawing commands on the canvas create_rectangle(left, top, right, bot,….) call canvas.update() to make things visible. Easy to add buttons and mouse create button and specify function to call when button is pressed. Button(window, text="Grow", command=grow).pack() bind mouse event to function called when mouse event happens canvas.bind(" ", command=plant) def plant(event) : ….. event.x …. event.y

© Peter Andreae Example Programs Flower : simple drawing Garden : list of coordinates functions with parameters buttons Tuples: collection of values "stuck together" in ( …) can treat the collections as a single value can access the elements using [ ] flower = ( 100, 150, 50) flower[2]

© Peter Andreae To Do: Write programs that Draw a table with four chairs Draw a collection of tables, given coordinates in two arrays tablesX = [100, 300, 500] tablesY = [150, 250, 150] Allow the user to place or move tables with the mouse