Lecture 3 - Overview. More about functions Operators Very briefly about naming conventions Graphical user interfaces (GUIs)
|
|
- Anastasia Robinson
- 5 years ago
- Views:
Transcription
1 Lecture 3 - Overview More about functions Operators Very briefly about naming conventions Graphical user interfaces (GUIs)
2 Function parameters Passed by reference, but the standard implication that the outside value is always changed when the parameter is altered inside the function doesn't hold. Immutables (such as integers) can't change so it won't change outside either Mutables (such as lists) are changed in the outside scope as well.
3 Parameter example # parameter_test.py def set_zero(x): print "id(x): ", id(x) if type(x) == list: x[0] = 0 elif type(x) == int: x = 0 $> python paremter_test.py id(a): id(b): id(x): id(x): [0, 1, 1] 1 a = [1,1,1] b = 1 print "id(a): ", id(a) print "id(b): ", id(b) set_zero(a) set_zero(b) print a print b
4 Functions - optional and named parameters def function_name(parameter_name=default_value): function_code_block When a function defines a parameter with a default value, that parameter and all afterwards are optional (and must also have default values). It is possible to pass only a later parameter
5 Optional parameter example # function_05.py def greeting(name="unknown", age=20): print "Hi %s. You are %i years old.""" % (name, age) greeting() greeting("carl") # Still works greeting(name="carl") # Equivalent greeting(age=45) # Gives the right result greeting("sara", 33) greeting(name = "Sara", age = 33) # Equivalent as previous line greeting(24) $> python function_05.py Hi Unknown. You are 20 years old. Hi Carl. You are 20 years old. Hi Carl. You are 20 years old. Hi Unknown. You are 45 years old. Hi Sara. You are 33 years old. Hi Sara. You are 33 years old. Hi 24. You are 20 years old.
6 Functions with many return values You can return several values If several variables are assigned the output, the will be defined consecutively The values are passed via a tuple # return_values_03.py def min_max(seq): return min(seq),max(seq) a = [3, 573, 234, 24] minimum, maximum = min_max(a) print minimum, maximum result = min_max(a) print result print result. class $> python return_values_03.py (3, 573) <type 'tuple'>
7 Operators Operators are characters with special meaning in the language. These include the standard mathematical operators as +, -, * and /, but also more programming oriented operators as [...] (for both getting and setting a value). Overloaded operators make it possible to use normal mathematical syntax for the builtin and own classes.
8 Operatorer are syntactical sugar Operators work in Python as special methods >>> a = "Hello " >>> b = "world!" >>> a + b 'Hello world!' >>> a. add (b) # Equivalent 'Hello world!' Note that a and b have different parts in the addition. a becomes the called object and b the argument. In other words: It's the add -method of a that will be called. A consequence of this is that addition not necessarily is a symmetric operation in Python. a + b can't be assumed to be the same as b + a.
9 Example 1: Addition with a class An overloaded operator can carry out anything. There is no requirement that operators shall do something that resembles the mathematical equivalent, even if it's strongly recommended. # -*- coding: utf-8 -*- # operators_01.py class ClassA: def init (self, text = "Default string"): self.text = text $> python operators_01.py Default stringdefault string def add (self, other): return ClassA(self.text + other.text) obj_1 = ClassA() obj_2 = ClassA() obj_3 = obj_1 + obj_2 print obj_3.text
10 Example 2: Different classes # -*- coding: utf-8 -*- # operators_02.py class ClassA: def init (self, text="instance of ClassA"): self.text = text def str (self): return self.text def add (self, other): return ClassA(str(self) + " + " + str(other)) class ClassB: def init (self, text="instance of ClassB"): self.text = text def str (self): return self.text def add (self, other): return "Addition not allowed with ClassB first." obj_a = ClassA() obj_b = ClassB() print obj_a + obj_a # => Instance of ClassA + Instance of ClassA print obj_a + obj_b # => Instance of ClassA + Instance of ClassB print obj_b + obj_a # => Addition not allowed with ClassB first.
11 Example 3: Indexing To read values getitem is used. To set values setitem is used. # -*- coding: utf-8 -*- # operators_03.py import random class ColorRepo: colors = ["Yellow", "White", "Black", "Pink", "Brown"] def getitem (self, index): return self. class.colors[index % len(self. class.colors)] cr = ColorRepo() for i in range(5): print cr[random.randint(0, 30000)]
12 Mathematical operators add (self,other) Addition, + sub (self,other) Subtraction, - mul (self,other) Multiplication, * div (self,other) Division, / floordiv (self,other) Integer division, // mod (self, other) Rest, % pow (self, other) Power of, ** or pow and (self, other) Logical and, and or (self, other) Logical or, or xor (self, other) Logical exclusive or, xor
13 Formatting and naming Variable names can't begin with a number. Conventions (PEP-8): 4 spaces for indentation most common Never mix spaces and tabs Limit all lines to a maximum of 79 characters. Classes begin with a capital letter Functions with lower case Multiple words in function names should preferably be separated with _: function_name
14 Graphical user interfaces
15 Graphical user interfaces (GUIs) Outline: Why are there graphical user interface? How are they built? Create graphics in Python. A few examples. Event handling.
16 Why have a GUI? Increase the usability Easier to learn Not always the best solution, it's easier to make scripts for command line programs for example. Is perceived as more user friendly
17 GUI-library TkInter De facto standard, comes with almost all standard installations. Stands for Tk interface and can be seen as a connection library between Tk GUI toolkit and Python (i.e. an adapter or wrapper) One of several ways of creating graphics in Python (other GUI library: wxpython, 3D graphics: VPython)
18 What objects does a GUI contain? Window Color area Frame Label Button Button
19 A first code example # first_example.py from Tkinter import * root = Tk() my_widget = Label(root, text="hello world") my_widget.pack() root.mainloop()
20 Breakdown of the program # first_example.py from Tkinter import * root = Tk() my_widget = Label(root, text="hello world") my_widget.pack() root.mainloop() The program follows the standard way in Tk to create widgets: 1. Create a main container, in this case a Tk-object. 2. Create a widget of the type you want, here a Label-object. 3. Define the characteristics of the widget, for example color and form. 4. Call the pack-method to add the widget in the interface. 5. Repeat step 2-4 for each widget. 6. Call the mainloop-method for the main container to show it and all the underlying widgets on the screen.
21 Packing widgets The packer is called for each widget with a request of how the widget should look and act. The requests are partly regarding placement and extension in a container, and partly about how the widget should change when the container changes size. The packer tries to meet all requests. If two requests are in conflict, the packer will take regard to the packing order, that is in which order pack has been called.
22 Placement A widget's placement is governed by the argument to the pack-method. Sides in the container are denoted with side and placement along the sides with anchor. How the widget should adapt to changes in the main container is set with expand and fill.
23 Example on placements # graphics02.py from Tkinter import * Button(text="A button").pack() mainloop() # graphics03.py from Tkinter import * Button(text="A button").pack(anchor=ne) mainloop() # graphics04.py from Tkinter import * Button(text="A button").pack(expand=yes, fill=both) mainloop()
24 Several widgets # graphics07.py from Tkinter import * Button(text="Button 1").pack(side=TOP, fill=x) Button(text="Button 2").pack(side=RIGHT, fill=y) Button(text="Button 3").pack(expand=YES, fill=both) mainloop()
25 Several widgets # graphics08.py from Tkinter import * Button(text="Button 2").pack(side=RIGHT, fill=y) Button(text="Button 1").pack(side=TOP, fill=x) Button(text="Button 3").pack(expand=YES, fill=both) mainloop()
26 Common widgets Label. Text label. Button. Clickable button. Radiobutton. Choose between of many. Checkbutton. Choose any number of alternatives. Entry. Read a shorter string. Frame. Arrange different groups of widget.
27 Multiple frames from Tkinter import * from tkmessagebox import * class TestGUI: def init (self, parent): # Create frames for the GUI frametop = Frame(parent) frametop.pack() framebottom=frame(parent, bg="blue") framebottom.pack(expand=yes, fill=both) frametopleft=frame(frametop) frametopleft.pack(side=left) frametopright=frame(frametop) frametopright.pack(side=right) # Add buttons Button(frameTopLeft, text="launch window", \ command=self.show_message).pack() Entry(frameTopRight).pack() Button(frameBottom, text="exit", \ command=parent.destroy).pack() def show_message(self): showinfo("message title", "Message text") if name == ' main ': root = Tk() root.title("test window") app = TestGUI(root) root.mainloop()
28 More advanced widgets Menu. Ordinary menus. Menubutton. Buttons that open a menu. Canvas. Painting area for composed graphics. Text. Text box for longer texts. Dialog boxes (not really widgets).
29 Classes and inheritance in TkInter Each type of widget in TkInter is a class. Each widget in a GUI is an object. The main program can be created as subclasses to TkInter-classes, for example Tk or Toplevel
30 Event handling The purpose of the GUI is to communication efficiently with the user, so it must be able to take input from the user and act according to this. Input can either be through the mouse, keyboard or other similar equipment. The focus on events change the program structure and the design. Suitable for modularisation and object oriented programming.
31 Linear or event driven program In a linear program: Things are carried out in a predetermined order. All input is done at predetermined occasions. In an event driven program: There is often a central waiting loop (main loop) Program pieces called event manager are executed depending on which event that occur. Note that event driven programs doesn't necessarily have to be dependent on a GUI.
32 A first event handler # events01.py from Tkinter import * def onleftclick(event): print event. class label.configure(text="you clicked on the left mouse button.") def onrightclick(event): label.configure(text="you clicked on the right mouse button.") root = Tk() label = Label(root, text="") label.pack(fill=x) button = Button(root, text="click on any mouse button") button.bind('<button-1>', onleftclick) # Connect left click button.bind('<button-3>', onrightclick) # Connect right click button.pack(fill=x) root.mainloop()
33 About the event handler Can be a function or a method Takes one argument, an Event-object that contain information about the event that took place and the widget that generated it. The same event handler can handle events from several different widgets. When the event handles is closed the program returns to the wait state again.
34 Defining an event An event is defined by a sequence of identifiers together with one or more modifiers. Identifiers are for example Button-n, Activate, FocusIn, FocusOut. Modifiers are for example Alt, Control och Shift. <Control-ButtonRelease-1> denotes that the left mouse button have been clicked and released, while the control-key was also pressed.
35 More common events Activate/Deactivate. The widget change state. Configure. The widget change size. Double-n. Mouse button n has been double-clicked. KeyPress-key. key (for example Alt) has been pressed. KeyRelease-key. key has been released. Enter. The mouse pointer is over the widget. Leave. The mouse pointer has left the widget.
36 The event object Other usable attributes for the event object are: time, serial, widget, x and y. # events05.py from Tkinter import * def onmouseclick(event): print 'You clicked with button', event.num root = Tk() button = Button(text="Click on me") button.bind('<any-button>', onmouseclick) button.pack(fill=x) root.mainloop()
37 Control variables Used to smoothly handle data from widgets. Can connect several widgets which in that way are kept synchronized. The content can either be changed by the user or by the program through the control variable.
38 Example with control variables # events07.py from Tkinter import * root = Tk() t = StringVar() # Create control variable t.set('this value is given to both objects.') # Set start value # The button's and the text box text is connected to the same variable. Button(root,textvariable=t).pack(fill=X) Entry(root, textvariable=t).pack(fill=x) root.mainloop()
39 Check boxes and control variables # checkbutton01.py from Tkinter import * def printform(): if haslicence.get(): print 'The person has a driver's license.' if hasowncar.get(): print 'The person has a car.' import sys sys.exit() root = Tk() haslicence = IntVar() Checkbutton(root,text = 'Driver's license', variable =haslicence).pack(anchor=w) hasowncar = IntVar() Checkbutton(root,text = 'Car',variable = hasowncar).pack(anchor=w) Button(root,text = 'Save',command = printform).pack(anchor=s) root.mainloop()
40 Group radio buttons # radiobutton01.py from Tkinter import * def onmealclick(): print mealvar.get() def ondrinkclick(): print drinkvar.get() root = Tk() mealvar = StringVar() meals = ['Breakfast','Lunch','Dinner'] for meal in meals: Radiobutton(root,command = onmealclick, text = meal, value = meal, variable = mealvar).pack(anchor=w) drinkvar = StringVar() drinks = ['Milk','Water','Soft drink'] for drink in drinks: Radiobutton(root,command = ondrinkclick, text = drink, value = drink, variable = drinkvar).pack(anchor=w) root.mainloop()
Lecture 3 - Overview. Object-oriented programming and classes Operators Very briefly about naming conventions Graphical user interfaces (GUIs)
Lecture 3 - Overview Object-oriented programming and classes Operators Very briefly about naming conventions Graphical user interfaces (GUIs) Object-oriented philosophy Object = Data + Algorithm An object
More informationLevel 3 Computing Year 2 Lecturer: Phil Smith
Level 3 Computing Year 2 Lecturer: Phil Smith We looked at: Debugging Previously BTEC Level 3 Year 2 Unit 16 Procedural programming Now Now we will look at: GUI applications. BTEC Level 3 Year 2 Unit 16
More informationENGR/CS 101 CS Session Lecture 15
ENGR/CS 101 CS Session Lecture 15 Log into Windows/ACENET (reboot if in Linux) Use web browser to go to session webpage http://csserver.evansville.edu/~hwang/f14-courses/cs101.html Right-click on lecture15.py
More informationProgramming Training. This Week: Tkinter for GUI Interfaces. Some examples
Programming Training This Week: Tkinter for GUI Interfaces Some examples Tkinter Overview Set of widgets designed by John K. Ousterhout, 1987 Tkinter == Tool Kit Interface Mean to be driven by Tcl (Toolkit
More information# arrange Label in parent widget
Much of today s software uses a point-and-click graphical user interface (GUI). The standard library modules Tkinter and Tix allow for portable, event-driven, GUI development in Python. A Python/Tkinter
More informationMid Unit Review. Of the four learning outcomes for this unit, we have covered the first two. 1.1 LO1 2.1 LO2 LO2
Lecture 8 Mid Unit Review Of the four learning outcomes for this unit, we have covered the first two. LO Learning outcome (LO) AC Assessment criteria for pass The learner can: LO1 Understand the principles
More informationApplication Note: Creating a Python Graphical User Interface. Matthew Roach March 31 st, 2014
Application Note: Creating a Python Graphical User Interface Matthew Roach March 31 st, 2014 Abstract: This document contains 2 portions. First, it provides an introduction into phase and the use of phase
More informationThinking in Tkinter. Thinking in Tkinter. by Stephen Ferg ferg.org) revised:
1 of 53 Thinking in Tkinter by Stephen Ferg (steve@ ferg.org) revised: 2005-07-17 This file contains the source code for all of the files in the Thinking in Tkinter series. If you print this file with
More informationCS2021 Week #6. Tkinter structure. GUI Programming using Tkinter
CS2021 Week #6 GUI Programming using Tkinter Tkinter structure Requires integra>on with Tk a GUI library Python program makes widgets and registers func>ons to handle widget events Program consist of theses
More informationIntroduction to Programming Using Python Lecture 6. Dr. Zhang COSC 1437 Spring, 2018 March 01, 2018
Introduction to Programming Using Python Lecture 6 Dr. Zhang COSC 1437 Spring, 2018 March 01, 2018 Chapter 9 GUI Programming Using Tkinter Getting started with Tkinter with a simple example. Code example:
More informationThis text is used together with Mark Pilgrims book Dive Into Python 3 for the Arthead course Python Fundamentals.
2 About this text This text is used together with Mark Pilgrims book Dive Into Python 3 for the Arthead course Python Fundamentals. The first part is written for Python 2 and at the end there is a section
More informationChapter 9 GUI Programming Using Tkinter. Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
Chapter 9 GUI Programming Using Tkinter 1 Motivations Tkinter is not only a useful tool for developing GUI projects, but also a valuable pedagogical tool for learning object-oriented programming. 2 Objectives
More informationCSE : Python Programming
CSE 399-004: Python Programming Lecture 08: Graphical User Interfaces with wxpython March 12, 2005 http://www.seas.upenn.edu/~cse39904/ Plan for today and next time Today: wxpython (part 1) Aside: Arguments
More informationTkinter Part II: Buttons, Lambda & Dynamic Content
Tkinter Part II: Buttons, Lambda & Dynamic Content July 8, 2015 Brian A. Malloy Slide 1 of 11 1. We further investigate Labels and Buttons and hook Python actions to these widgets. We present lambda functions,
More informationCS 112: Intro to Comp Prog
CS 112: Intro to Comp Prog Tkinter Layout Managers: place, pack, grid Custom Frames Widgets In-depth StringVar tkfont Upcoming Tk To use Tkinter Widgets (components: buttons, labels, etc). You must import
More informationGraphical User Interfaces
to visualize Graphical User Interfaces 1 2 to visualize MCS 507 Lecture 12 Mathematical, Statistical and Scientific Software Jan Verschelde, 19 September 2011 Graphical User Interfaces to visualize 1 2
More informationQuestion Possible Points Earned Points Graded By GUI 22 SQL 24 XML 20 Multiple Choice 14 Total Points 80
CS 1803 Spring 2011 Exam 3 KEY Name: Section: Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking
More informationTkinter: Input and Output Bindings. Marquette University
Tkinter: Input and Output Bindings Marquette University Tkinter Variables Tkinter contains a useful mechanism to connect widgets to variables This allows us to have variables change when widgets do and
More informationCIS192 Python Programming
CIS192 Python Programming Graphical User Interfaces Robert Rand University of Pennsylvania November 19, 2015 Robert Rand (University of Pennsylvania) CIS 192 November 19, 2015 1 / 20 Outline 1 Graphical
More informationUser Interfaces. getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy
User Interfaces 1 Command Line Interfaces getting arguments of the command line a command line interface to store points fitting points with polyfit of numpy 2 Encapsulation by Object Oriented Programming
More informationCS 2316 Exam 2 Summer 2011
CS 2316 Exam 2 Summer 2011 Name : Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam
More informationGraphical User Interfaces with Perl/Tk. Event Driven Programming. Structure of an Event-Driven Program. An introduction
Graphical User Interfaces with Perl/Tk An introduction Event Driven Programming In functional programming, what happens when is determined (almost) entirely by the programmer. The user generally has a
More informationChapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationSelected GUI elements:
Selected GUI elements: Element tkinter Class Description Frame Frame Holds other GUI elements Label Label Displays uneditable text or icons Button Button Performs an action when the user activates it Text
More informationIntroduction to VTK and Python. Filip Malmberg Uppsala universitet
Introduction to VTK and Python Filip Malmberg filip@cb.uu.se IT Uppsala universitet Todays lecture Introduction to the Visualization Toolkit (VTK) Some words about the assignments Introduction to Python
More informationA GUI for DFT and Orthogonal DWT in Tkinter
A GUI for DFT and Orthogonal DWT in Tkinter Tariq Javid Ali, Pervez Akhtar, Muhammad Faris Hamdard Institute of Engineering & Technology Hamdard University Karachi-74600, Pakistan Email: {tariq.javid pervez.akhtar
More informationCIS192 Python Programming
CIS192 Python Programming User Interfaces (Graphical and Text) Eric Kutschera University of Pennsylvania March 20, 2015 Eric Kutschera (University of Pennsylvania) CIS 192 March 20, 2015 1 / 23 Final Project
More informationTeaching London Computing
Teaching London Computing A Level Computer Science Programming GUI in Python William Marsh School of Electronic Engineering and Computer Science Queen Mary University of London How the Session Works Outline
More informationCSE : Python Programming
CSE 399-004: Python Programming Lecture 2: Data, Classes, and Modules January 22, 2007 http://www.seas.upenn.edu/~cse39904/ Administrative things Teaching assistant Brian Summa (bsumma @ seas.upenn.edu)
More informationLecture #15: Generic Functions and Expressivity. Last modified: Wed Mar 1 15:51: CS61A: Lecture #16 1
Lecture #15: Generic Functions and Expressivity Last modified: Wed Mar 1 15:51:48 2017 CS61A: Lecture #16 1 Consider the function find: Generic Programming def find(l, x, k): """Return the index in L of
More informationPart 3. Useful Python
Part 3 Useful Python Parts one and two gave you a good foundation in the Python language and a good understanding of software design. You ve built some substantial applications, and hopefully you ve built
More informationCS 112 Project Assignment: Visual Password
CS 112 Project Assignment: Visual Password Instructor: Dan Fleck Overview In this project you will use Python to implement a visual password system. In the industry today there is ongoing research about
More informationThis course is designed for anyone who needs to learn how to write programs in Python.
Python Programming COURSE OVERVIEW: This course introduces the student to the Python language. Upon completion of the course, the student will be able to write non-trivial Python programs dealing with
More informationIntroduction to Python
Introduction to Python خانه ریاضیات اصفهان فرزانه کاظمی زمستان 93 1 Why Python? Python is free. Python easy to lean and use. Reduce time and length of coding. Huge standard library Simple (Python code
More informationOverview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017
Overview of OOP Dr. Zhang COSC 1436 Summer, 2017 7/18/2017 Review Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in square brackets: l = [1, 2, "a"] (access by index, is mutable
More informationProfessor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators
1 Professor: Sana Odeh odeh@courant.nyu.edu Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators Review What s wrong with this line of code? print( He said Hello ) What s wrong with
More informationECE 364 Software Engineering Tools Laboratory. Lecture 7 Python: Object Oriented Programming
ECE 364 Software Engineering Tools Laboratory Lecture 7 Python: Object Oriented Programming 1 Lecture Summary Object Oriented Programming Concepts Object Oriented Programming in Python 2 Object Oriented
More informationOutline. general information policies for the final exam
Outline 1 final exam on Tuesday 5 May 2015, at 8AM, in BSB 337 general information policies for the final exam 2 some example questions strings, lists, dictionaries scope of variables in functions working
More informationUser Interfaces. MCS 507 Lecture 11 Mathematical, Statistical and Scientific Software Jan Verschelde, 16 September Command Line Interfaces
User 1 2 MCS 507 Lecture 11 Mathematical, Statistical and Scientific Software Jan Verschelde, 16 September 2011 User 1 2 command line interfaces Many programs run without dialogue with user, as $ executable
More informationDownloaded from Chapter 2. Functions
Chapter 2 Functions After studying this lesson, students will be able to: Understand and apply the concept of module programming Write functions Identify and invoke appropriate predefined functions Create
More informationIntroduction to Python
Introduction to Python Version 1.1.5 (12/29/2008) [CG] Page 1 of 243 Introduction...6 About Python...7 The Python Interpreter...9 Exercises...11 Python Compilation...12 Python Scripts in Linux/Unix & Windows...14
More informationGetting Started p. 1 Obtaining Tcl/Tk p. 1 Interactive Execution p. 1 Direct Execution p. 4 Reading this Book p. 6 Requirements for Networking
Foreword p. xi Acknowledgments p. xiii Getting Started p. 1 Obtaining Tcl/Tk p. 1 Interactive Execution p. 1 Direct Execution p. 4 Reading this Book p. 6 Requirements for Networking Examples p. 7 Requirements
More informationSTSCI Python Introduction. Class URL
STSCI Python Introduction Class 2 Jim Hare Class URL www.pst.stsci.edu/~hare Each Class Presentation Homework suggestions Example files to download Links to sites by each class and in general I will try
More informationCourse Outline - COMP150. Lectures and Labs
Course Outline - COMP150 Lectures and Labs 1 The way of the program 1.1 The Python programming language 1.2 What is a program? 1.3 What is debugging? 1.4 Experimental debugging 1.5 Formal and natural languages
More informationPTN-202: Advanced Python Programming Course Description. Course Outline
PTN-202: Advanced Python Programming Course Description This 4-day course picks up where Python I leaves off, covering some topics in more detail, and adding many new ones, with a focus on enterprise development.
More informationIntroduction to Python
Introduction to Python EECS 4415 Big Data Systems Tilemachos Pechlivanoglou tipech@eecs.yorku.ca 2 Background Why Python? "Scripting language" Very easy to learn Interactive front-end for C/C++ code Object-oriented
More informationCAS London CPD Day February 16
Practical Sheet: GUI Programming This sheet is a set of exercises for introducing GUI programming in Python using Tkinter, assuming knowledge of basic Python programming. All materials are at http://www.eecs.qmul.ac.uk/~william/cas-london-2016.html
More informationLecture 1 August 9, 2017
Programming in Haskell S P Suresh http://www.cmi.ac.in/~spsuresh Lecture 1 August 9, 2017 Administrative Mondays and Wednesdays at 9.10 am at Lecture Hall 6 Evaluation: Quizzes, 4 5 programming assignments,
More informationCS177 Recitation. Functions, Booleans, Decision Structures, and Loop Structures
CS177 Recitation Functions, Booleans, Decision Structures, and Loop Structures Functions Collection of instructions that perform a task as: o Printing your name and course. o Calculating the average of
More informationIntroduction to Python (All the Basic Stuff)
Introduction to Python (All the Basic Stuff) 1 Learning Objectives Python program development Command line, IDEs, file editing Language fundamentals Types & variables Expressions I/O Control flow Functions
More informationCS 2316 Exam 3 Summer 2014
CS 2316 Exam 3 Summer 2014 Name : Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam
More informationFundamentals of Programming. Functions Redux. Event-based Programming. File and Web IO. November 4th, 2014
15-112 Fundamentals of Programming Functions Redux. Event-based Programming. File and Web IO. November 4th, 2014 Today Briefly show file and web IO. Revisit functions. Learn a bit more about them. Event-based
More informationCS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG
CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG 1 Notice Assignments Reading Assignment: Chapter 3: Introduction to Parameters and Objects The Class 10 Exercise
More informationHello, World! An Easy Intro to Python & Programming. Jack Rosenthal
An Easy Intro to Python & Programming Don t just buy a new video game, make one. Don t just download the latest app, help design it. Don t just play on your phone, program it. No one is born a computer
More informationData Structures (list, dictionary, tuples, sets, strings)
Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access
More information1. BASICS OF PYTHON. JHU Physics & Astronomy Python Workshop Lecturer: Mubdi Rahman
1. BASICS OF PYTHON JHU Physics & Astronomy Python Workshop 2017 Lecturer: Mubdi Rahman HOW IS THIS WORKSHOP GOING TO WORK? We will be going over all the basics you need to get started and get productive
More informationPython I. Some material adapted from Upenn cmpe391 slides and other sources
Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationLecture #16: Generic Functions and Expressivity. Last modified: Fri Feb 26 19:16: CS61A: Lecture #16 1
Lecture #16: Generic Functions and Expressivity Last modified: Fri Feb 26 19:16:38 2016 CS61A: Lecture #16 1 Consider the function find: Generic Programming def find(l, x, k): """Return the index in L
More information\n is used in a string to indicate the newline character. An expression produces data. The simplest expression
Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of
More informationObject Model Comparisons
Object Model Comparisons 1 Languages are designed, just like programs Someone decides what the language is for Someone decides what features it's going to have Can't really understand a language until
More informationPython Scripting for Computational Science
Hans Petter Langtangen Python Scripting for Computational Science Third Edition With 62 Figures 43 Springer Table of Contents 1 Introduction... 1 1.1 Scripting versus Traditional Programming... 1 1.1.1
More informationFormulas and Functions
Conventions used in this document: Keyboard keys that must be pressed will be shown as Enter or Ctrl. Controls to be activated with the mouse will be shown as Start button > Settings > System > About.
More informationPIC 16, Fall Variables, Dynamically-typed, Mutable, Immutable, Functions. Michael Andrews. October 1, Department of Mathematics UCLA
PIC 16, Fall 2018 Variables, Dynamically-typed, Mutable, Immutable, Functions Michael Andrews Department of Mathematics UCLA October 1, 2018 Office hours reminder M 1:30-2:45pm (Michael) T 1-2pm (Sam),
More informationPython: common syntax
Lab 09 Python! Python Intro Main Differences from C++: True and False are capitals Python floors (always down) with int division (matters with negatives): -3 / 2 = -2 No variable data types or variable
More information[CHAPTER] 1 INTRODUCTION 1
FM_TOC C7817 47493 1/28/11 9:29 AM Page iii Table of Contents [CHAPTER] 1 INTRODUCTION 1 1.1 Two Fundamental Ideas of Computer Science: Algorithms and Information Processing...2 1.1.1 Algorithms...2 1.1.2
More information(IUCAA, Pune) kaustubh[at]iucaa[dot]ernet[dot]in.
Basics of Python - 2 by Kaustubh Vaghmare (IUCAA, Pune) E-mail: kaustubh[at]iucaa[dot]ernet[dot]in 1 of 54 Sunday 16 February 2014 05:30 PM Our First Program - Rewritten! Let us introduce the following
More informationLecture 19. Operators and Abstraction
Lecture 19 Operators and Abstraction Announcements Reading Tuesday: Chapter 18 Thursday reading online Assignments A4 due tonight at Midnight 10 pts per day late Consultants available tonight A5 posted
More informationTcl/Tk lecture. What is the Wish Interpreter? CIS 410/510 User Interface Programming
Tcl/Tk lecture CIS 410/510 User Interface Programming Tool Command Language TCL Scripting language for developing & using GUIs Allows generic programming variables, loops, procedures Embeddable into an
More informationPython for Scientific Computations and Control
Python for Scientific Computations and Control 1 Python for Scientific Computations and Control Project Report Georg Malte Kauf Python for Scientific Computations and Control 2 Contents 1 Introduction
More informationEasy Graphical User Interfaces
Easy Graphical User Interfaces with breezypythongui Types of User Interfaces GUI (graphical user interface) TUI (terminal-based user interface) UI Inputs Outputs Computation Terminal-Based User Interface
More informationhttps://lambda.mines.edu Why study Python in Principles of Programming Languages? Multi-paradigm Object-oriented Functional Procedural Dynamically typed Relatively simple with little feature multiplicity
More informationGlossary. For Introduction to Programming Using Python By Y. Daniel Liang
Chapter 1 Glossary For Introduction to Programming Using Python By Y. Daniel Liang.py Python script file extension name. assembler A software used to translate assemblylanguage programs into machine code.
More informationGIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes
GIS 4653/5653: Spatial Programming and GIS More Python: Statements, Types, Functions, Modules, Classes Statement Syntax The if-elif-else statement Indentation and and colons are important Parentheses and
More informationCSC 110 Final Exam. ID checked
ID checked CSC 110 Final Exam Name: Date: 1. Write a Python program that asks the user for a positive integer n and prints out n evenly spaced values between 0 and 10. The values should be printed with
More informationBabu Madhav Institute of Information Technology, UTU 2015
Five years Integrated M.Sc.(IT)(Semester 5) Question Bank 060010502:Programming in Python Unit-1:Introduction To Python Q-1 Answer the following Questions in short. 1. Which operator is used for slicing?
More informationPYTHON FOR KIDS A Pl ayfu l I ntrodu ctio n to Prog r am m i ng J a s o n R. B r i g g s
PYTHON FO R K I D S A P l ay f u l I n t r o d u c t i o n to P r o g r a m m i n g Jason R. Briggs Index Symbols and Numbers + (addition operator), 17 \ (backslash) to separate lines of code, 235 in strings,
More informationEVENT-DRIVEN PROGRAMMING
LESSON 13 EVENT-DRIVEN PROGRAMMING This lesson shows how to package JavaScript code into self-defined functions. The code in a function is not executed until the function is called upon by name. This is
More informationAccelerating Information Technology Innovation
Accelerating Information Technology Innovation http://aiti.mit.edu/program/philippines-summer-2012/ Philippines Summer 2012 Lecture 1 Introduction to Python June 19, 2012 Agenda About the Course What is
More informationLecture 18. Classes and Types
Lecture 18 Classes and Types Announcements for Today Reading Today: See reading online Tuesday: See reading online Prelim, Nov 6 th 7:30-9:30 Material up to next class Review posted next week Recursion
More informationPython Scripting for Computational Science
Hans Petter Langtangen Python Scripting for Computational Science Third Edition With 62 Figures Sprin ger Table of Contents 1 Introduction 1 1.1 Scripting versus Traditional Programming 1 1.1.1 Why Scripting
More informationNotes on Chapter 1 Variables and String
Notes on Chapter 1 Variables and String Note 0: There are two things in Python; variables which can hold data and the data itself. The data itself consists of different kinds of data. These include numbers,
More informationCS 2316 Exam 3 Fall 2011
CS 2316 Exam 3 Fall 2011 Name : 1. (2 points) Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking
More informationTable of Contents EVALUATION COPY
Table of Contents Introduction... 1-2 A Brief History of Python... 1-3 Python Versions... 1-4 Installing Python... 1-5 Environment Variables... 1-6 Executing Python from the Command Line... 1-7 IDLE...
More informationTable of Contents. Preface... xxi
Table of Contents Preface... xxi Chapter 1: Introduction to Python... 1 Python... 2 Features of Python... 3 Execution of a Python Program... 7 Viewing the Byte Code... 9 Flavors of Python... 10 Python
More informationHere n is a variable name. The value of that variable is 176.
UNIT II DATA, EXPRESSIONS, STATEMENTS 9 Python interpreter and interactive mode; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence
More information(CC)A-NC 2.5 by Randall Munroe Python
http://xkcd.com/353/ (CC)A-NC 2.5 by Randall Munroe Python Python: Operative Keywords Very high level language Language design is focused on readability Mulit-paradigm Mix of OO, imperative, and functional
More information1B1b Classes in Java Part I
1B1b Classes in Java Part I Agenda Defining simple classes. Instance variables and methods. Objects. Object references. 1 2 Reading You should be reading: Part I chapters 6,9,10 And browsing: Part IV chapter
More information9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C
Overview The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments
More informationCS 2316 Individual Homework 5 Joint Probability Out of 100 points
CS 2316 Individual Homework 5 Joint Probability Out of 100 points Files to submit: 1. HW5.py This is an INDIVIDUAL Assignment: Collaboration at a reasonable level will not result in substantially similar
More informationPython Review IPRE
Python Review 2 Jay Summet 2005-12-31 IPRE Outline Compound Data Types: Strings, Tuples, Lists & Dictionaries Immutable types: Strings Tuples Accessing Elements Cloning Slices Mutable Types: Lists Dictionaries
More informationPython Programming, bridging course 2011
Python Programming, bridging course 2011 About the course Few lectures Focus on programming practice Slides on the homepage No course book. Using online resources instead. Online Python resources http://www.python.org/
More informationLecture 21. Programming with Subclasses
Lecture 21 Programming with Subclasses Announcements for Today Reading Today: See reading online Tuesday: Chapter 7 Prelim, Nov 10 th 7:30-9:00 Material up to Today Review has been posted Recursion + Loops
More informationFunctional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute
Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Module # 02 Lecture - 03 Characters and Strings So, let us turn our attention to a data type we have
More informationThe C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)
The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments
More information06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python
CS95003 - Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / 2014 Subjects 1) Beginning with Python 2) Variables 3) Strings 4) Basic arithmetic operators 5) Flow control 6) Comparison
More informationC++ for Python Programmers
C++ for Python Programmers Adapted from a document by Rich Enbody & Bill Punch of Michigan State University Purpose of this document This document is a brief introduction to C++ for Python programmers
More informationCS61A Lecture 18. Amir Kamil UC Berkeley March 4, 2013
CS61A Lecture 18 Amir Kamil UC Berkeley March 4, 2013 Announcements HW6 due on Thursday Trends project due tomorrow Ants project out Persistent Local State The parent contains local state A function with
More informationLecture 21. Chapter 12 More Python Containers
Lecture 21 Chapter 12 More Python Containers 12.1 Two Familiar Containers: list and tuple 12.2 Dictionaries 12.3 Containers of containers 12.4 Set and Frozenset 12.5 Arrays Chapter 12 More Python Containers
More informationDecisions, Decisions. Testing, testing C H A P T E R 7
C H A P T E R 7 In the first few chapters, we saw some of the basic building blocks of a program. We can now make a program with input, processing, and output. We can even make our input and output a little
More informationIntroduction to computers and Python. Matthieu Choplin
Introduction to computers and Python Matthieu Choplin matthieu.choplin@city.ac.uk http://moodle.city.ac.uk/ 1 Objectives To get a brief overview of what Python is To understand computer basics and programs
More information