CS10 The Beauty and Joy of Computing Lecture #20 Pyhton II 2014-11-12 UC Berkeley EECS Lecturer Gerald.

Slides:



Advertisements
Similar presentations
An Introduction to Programming By :- Vishal Hirani B.Tech II year (CSE)
Advertisements

The Beauty and Joy of Computing Lecture #19 Higher Order Functions II Instructor: Sean Morris Twitter Can Tell Whether Your Community Is Happy or Not
COMPUTER PROGRAMMING Task 1 LEVEL 6 PROGRAMMING: Be able to use a text based language like Python and JavaScript & correctly use procedures and functions.
CS61A Lecture 8 Data Abstraction Tom Magrino and Jon Kotker UC Berkeley EECS June 28, 2012.
Lists CMSC 201. Overview Today we will learn about: For loops.
The Beauty and Joy of Computing Lecture #18 Higher Order Functions I Instructor: Sean Morris
Lecture 03 – Sequences of data.  At the end of this lecture, students should be able to:  Define and use functions  Import functions from modules 
The Beauty and Joy of Computing Lecture #18 Besides Blocks I: Intro to Python Amazon Dash is Not an April Fools Joke UC Berkeley EECS Head TA Michael Ball.
CS10 The Beauty and Joy of Computing Lecture #10 Social Implications of Computing Having just returned from the UC Online Pilot Project Workshop,
CS10 The Beauty and Joy of Computing Lecture #11 : Recursion II Microsoft filed a patent that proposed to use the 3D depth camera to estimate.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
CS10 The Beauty and Joy of Computing Lecture #17 Higher Order Functions I Silicon (normally what processors are made of) is rigid and expensive,
CS10 The Beauty and Joy of Computing Lecture #25 : Tree Recursion The newly released (and much- hyped) Microsoft Kinect system for the XBOX.
CS10 The Beauty and Joy of Computing Lecture #23 : Limits of Computing Thanks to the success of the Kinect, researchers all over the world believe.
CS39N The Beauty and Joy of Computing Lecture #6 : Programming Paradigms In response to a 30,000+ signature petition, British PM Gordon Brown.
CS10 The Beauty and Joy of Computing Lecture #11 : Recursion II Will Apple continue to thrall its users with outstanding technology amidst tons.
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 Control of Flow.
TEACHING PROGRAMMING BY ITERATIVE DEEPENING Dr. Mark Lee | School of Computer Science, University of Birmingham
CS61A Lecture 2 Functions and Applicative Model of Computation Tom Magrino and Jon Kotker UC Berkeley EECS June 19, 2012.
The Beauty and Joy of Computing Lecture #1 Welcome; Abstraction Watch the student testimonials about the course, what it means to them, and how it has.
More Looping Structures
UC Berkeley EECS Head TA Michael Ball The Beauty and Joy of Computing Beyond Blocks Python Session 2: Data Structures UC Berkeley EECS TA Peter Sujan (thanks.
Com Functional Programming Higher Order Functions and Computation Patterns (I) Marian Gheorghe Lecture 10 Module homepage Mole &
CS 127 Writing Simple Programs.  Stages involved  Analyze the problem  Understand as much as possible what is trying to be solved  Determine Specifications.
First Program  Open a file  In Shell  Type into the file: 3  You did it!!! You wrote your first instruction, or code, in python!
Files and Dictionaries CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
UC Berkeley EECS Sr Lecturer SOE Dan Garcia printing-aims-to-prevent-a-piracy-plague/ Quest.
The Beauty and Joy of Computing Lecture #3 : Creativity & Abstraction UC Berkeley EECS Lecturer Gerald Friedland.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 12: A few other things.
The role of data mining in the last presidential election. A mind-blowing piece on how the Obama campaign used various sources of data to target voters.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Python Programming Using Variables and input. Objectives We’re learning to build functions and to use inputs and outputs. Outcomes Build a function Use.
too.
Lesson 6. Python 3.3 Objectives. In this lesson students will learn how to output data to the screen and request input from the user. Students will also.
# Author: David Foltz # # Notice: Orginal Code Idea for program taken from Python v3.2.2 Documentation def Fibonacci(): """Print a Fibonacci series with.
Python The tutorial
The Beauty and Joy of Computing Lecture #10 Social Implications of Computing Online education now has a player in the open access / free education space,
Programming for GCSE 1.0 Beginning with Python T eaching L ondon C omputing Margaret Derrington KCL Easter 2014.
For Loops CMSC 201. Overview Today we will learn about: For loops.
CS10: The Beauty and Joy of Computing Lecture #22 Limits of Computing Warning sign posted at Stern Hall. Also, Apple releases new operating.
The Beauty and Joy of Computing Lecture #5 Programming Paradigms invent.citris-uc.org
Programming Seminar 2009 Night 0. Why we’re holding this seminar You’re probably not a computer science major – Or even anything remotely close (e.g.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
The Beauty and Joy of Computing Lecture #11 Recursion II Toby Shachman created this amazing spatial programming language called “Recursive Drawing” that.
The Beauty and Joy of Computing Lecture #12 Social Implications of Computing I Online education now has a player in the open access / free education space,
UC Berkeley EECS Sr Lecturer SOE Dan Garcia printing-aims-to-prevent-a-piracy-plague/ Quest.
CSCI 931 III–1 Copyright © 2010 Thomas W. Doeppner. All rights reserved. CS 931: Dictionaries.
Today's Ninja Challenge: Write Your First Computer Game!
CS61A Lecture 1 Introduction and Basics Tom Magrino and Jon Kotker UC Berkeley EECS June 18, 2012.
First Program  Open a file  In Shell  Type into the file: 3  You did it!!! You wrote your first instruction, or code, in python!
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
Python: Iteration Damian Gordon. Python: Iteration We’ll consider four ways to do iteration: – The WHILE loop – The FOR loop – The DO loop – The LOOP.
PythonCyc and other APIs A Python package to access Pathway Tools and its data using the Python programming language Mario Latendresse March 2016.
Getting Started With Python Brendan Routledge
UC Berkeley EECS Lecturer SOE Dan Garcia The success of Apple’s Siri (only available on the iPhone 4S) has sparked competition, to be sure. Google’s IRIS.
Machine Language Computer languages cannot be directly interpreted by the computer – they are not in binary. All commands need to be translated into binary.
CSC 1010 Programming for All Lecture 5 Functions Some material based on material from Marty Stepp, Instructor, University of Washington.
More about Iteration Victor Norman CS104. Reading Quiz.
Topic: Functions – Part 1
Topic: Iterative Statements – Part 1 -> for loop
Intro To Pete Alonzi University of Virginia Library
CS-401 Compute Architecture & Assembly Language Programming
LING 388: Computers and Language
Introduction to Python
CS-401 Computer Architecture & Assembly Language Programming
CMSC201 Computer Science I for Majors Lecture 08 – For Loops
Topic: Iterative Statements – Part 2 -> for loop
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
Lecture 17 – Practice Exercises 3
Presentation transcript:

CS10 The Beauty and Joy of Computing Lecture #20 Pyhton II UC Berkeley EECS Lecturer Gerald Friedland

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (2) Friedland How’s your Python experience so far? a) I’d rather stay with Snap! b) Neutral c) I love Python! d) Not sure yet. Peer Instruction

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (3) Friedland Python II: Let’s get comfortable… meet-julius-huge-yellow-pet-python-18.html

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (4) Friedland Python II  Defining a function  List and dictionaries  HOFs in Python  APIs  A game in Python

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (5) Friedland Defining a Function A function/method/procedure/block is defined with def def function1(): print “Hello World” def function2(parameter1, paramter2): print parameter1+parameter2

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (6) Friedland Defining a Function Remember this? def fib(n): a,b=0,1 while a < n: print(a) a,b=b, a+b Let’s give it a try…

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (7) Friedland Iterators For iterates over lists list = [2, 4, 6, 8] sum = 0 for num in list: sum = sum + num print("The sum is:", sum) Let’s give it a try…

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (8) Friedland How to iterate over a range… …with range: list = range(1,10) sum = 0 for num in list: sum = sum + num print("The sum is:", sum) Let’s give it a try…

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (9) Friedland Speaking of list… Lists can contain anything list = [1,2,3] list = [“Hello”,”World”] list = [“Hello”,1,”World”,2.3] list = [[1,2],[3,4],[5,6]] list = [(1,2),[3,4],5,6] Let’s give it a try…

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (10) Friedland List Comprehension How to work with Lists list = range(1,5)+range(5,10) elem = list[3] elems = list[3:5] list2 = list[4:] list3 = list[:9] Let’s give it a try…

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (11) Friedland List Comprehension (more) How to work with Lists fruits = ['Banana', 'Apple', 'Lime'] loud_fruits = [fruit.upper() for fruit in fruits] list(enumerate(fruits)) Let’s give it a try…

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (12) Friedland List Comprehension (more) How to work with Lists List=[0,1,2,3,4,5,6,7,8,9] list.reverse() list.sort() list.count(10) list.insert(5,123) Let’s give it a try…

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (13) Friedland Dictionaries stuff = {'name': 'Zed', 'age': 39, 'height': 6 * } print stuff[‘name’] Let’s give it a try…

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (14) Friedland HOFs HOFs are part of Python too! map(upper, ['sentence', 'fragment']) def is_even(x): return (x % 2) == 0 filter(is_even, range(10)) Let’s give it a try…

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (15) Friedland APIs APIs = Application Programming Interface import pygame pygame.init() Let’s give it a try… - APIs allow blackbox use of pre-programmed elements - Provide abstraction, save work

UC Berkeley CS10 “The Beauty and Joy of Computing” : Python II (16) Friedland A Game! Let’s give it a try…  Python very productive language  Pacman game in under 1000 lines of code.  Works platform independent (Linux, MacOS X, Windows, iOS, etc…)