Welcome Back to CS 5 Black!

Slides:



Advertisements
Similar presentations
CS107 Introduction to Computer Science Loops. Instructions Pseudocode Assign values to variables using basic arithmetic operations x = 3 y = x/10 z =
Advertisements

Problem Solving Strategies
CS 102 Computers In Context (Multimedia)‏ 03 / 25 / 2009 Instructor: Michael Eckmann.
Math 010 online work that was due today at the start of class:
CS61A Lecture 2 Functions and Applicative Model of Computation Tom Magrino and Jon Kotker UC Berkeley EECS June 19, 2012.
How to Survive Mrs. Grace’s English Class My Expectations and a Quiz…
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Arithmetic and Geometric Series (11.5) Short cuts.
EECS 110: Lec 5: List Comprehensions Aleksandar Kuzmanovic Northwestern University
The building blocks of functional computing data, sequences conditionals recursion CS 121 today List Comprehensions map and applications.
PROCEDURES IN MR. F’S CLASS WHAT ARE THE RULES AND PROCEDURES I NEED TO KNOW?
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.
Python Let’s get started!.
Seminar 6. Agenda Housekeeping  Mid-term check-in  Saving documents Relative vs. Absolute Cell References Fill Handle Functions  Auto SUM  AVERAGE.
Introduction to Programming Python Lab 3: Arithmetic 22 January PythonLab3 lecture slides.ppt Ping Brennan
CSx 4091 – Python Programming Spring 2013 Lecture L2 – Introduction to Python Page 1 Help: To get help, type in the following in the interpreter: Welcome.
1 Test Next Period Summer 3, 2015 Midterm Exam. 2 Type of Exam Possible exam questions areas follows:  True-False Questions  Multiple Choice Questions.
Monday August 29, 2011 (TAKS Chemistry Formula Chart and Chemistry EOC Reference Packet; Preparation of Chemistry Notebook)
Input, Output and Variables GCSE Computer Science – Python.
Introduction to Programming
Math operations 9/19/16.
Week 2 - Wednesday CS 121.
CS1022 Computer Programming & Principles
Current Events By: Hector Martinez.
Algorithmic complexity: Speed of algorithms
Python Let’s get started!.
EECS 110: Lec 5: List Comprehensions
Formatting Output.
EECS 110: Lec 5: List Comprehensions
COMPSCI 107 Computer Science Fundamentals
Introduction to Programming
Classroom Procedures for Ms. Bishop Room 140.
CS 115 Lecture 8 Structured Programming; for loops
Functions CIS 40 – Introduction to Programming in Python
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Structured Programming; for loops Taken from notes by Dr. Neil Moore
The CS 5 Black Post Penguins Invade Dormitory
The CS 5 Black Times Penguin Leads Surfing Trip
1 Python Lab #1 Intro to Python Adriane Huber Debbie Bartlett.
The CS5 Times Eager Penguins Invade Computer Lab
Computer Science and an introduction to Pascal
Number and String Operations
CompSci 101 Introduction to Computer Science
Introduction to Programming
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
9th Grade Registration.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
“If you can’t write it down in English, you can’t code it.”
Introduction to Programming Using Python PART 1
Programming Fundamentals
Introduction to Programming
Excel Lookup Formulas Welcome! with Cindy Kredo
Algorithmic complexity: Speed of algorithms
Test Next Week Summer 3, 2016 Midterm Exam
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Effective search techniques
Algorithmic complexity: Speed of algorithms
Introduction to Programming
Ch 8.2.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
What is a Function? Takes one or more arguments, or perhaps none at all Performs an operation Returns one or more values, or perhaps none at all Similar.
More Basics of Python Common types of data we will work with
def-ining a function A function as an execution control structure
Functions, Procedures, and Abstraction
functions are also data! other functions as input!
Functions John R. Woodward.
Psychology Participant Pool
Functions and Abstraction
Presentation transcript:

Welcome Back to CS 5 Black! PENGUIN GETS $1B IN FUNDING San Jose (AFP): A penguin who was chased out of a Harvey Mudd College computer science lab by an angry mob has turned the experience into a startup with a billion dollars in venture funding. The new company will market an app that helps penguins track and dodge predators. “The market is huge,” said one investor. “Antarctica is full of penguins and they don’t have any way to know where the sharks are. We expect massive returns.” The founding penguin will celebrate in a local sushi restaurant. Please pick up these lecture notes & a blank “worksheet”!

Defining Your Own Functions! def dbl(x): return 2 * x x dbl 2 * x Notice the indentation. This is done using “tab” and it’s absolutely necessary! def dbl(myArgument): myResult = 2 * myArgument return myResult

Docstrings! def dbl(x): ”””This function takes a number x and returns 2 * x””” return 2 * x This is sort of like teaching your programs to talk to you!

Docstrings…and Comments # Doubling program # Author: Ran Libeskind-Hadas # Date: August 27, 2011 def dbl(x): ”””This function takes a number x and returns 2 * x””” return 2 * x

Composition of Functions def quad(x): return 4 * x x quad 4 * x def quad(x): return dbl(dbl(x)) Doubly cool! In math, you can compose functions: f(g(x)). You can do the same in Python.

Multiple Arguments... x, y myFunc x + 42 * y # myFunc That’s a kind of a funky function! # myFunc # Author: Ran Libeskind-Hadas # Date: August 27, 2011 def myFunc(x, y): """returns x + 42 * y""" return x + 42 * y

Mapping with Python... def dbl(x): """returns 2 * x""" return 2 * x >>> list(map(dbl, [0, 1, 2, 3, 4])) [0, 2, 4, 6, 8] def evens(n): myList = range(n) doubled = list(map(dbl, myList)) return doubled Alternatively…. def evens(n): return list(map(dbl, range(n)))

reduce-ing with Python... from functools import reduce def add(x, y): """returns x + y""" return x + y >>> reduce(add, [1, 2, 3, 4]) 10 add add add

Google’s “Secret” This is what put Google on the map! Note that Google didn’t invent MapReduce. But what Dean and Ghemawat did was to show how you could efficiently apply this powerful concept to huge datasets using large clusters of computers.

Try This… Write a function called span that returns the difference between the maximum and minimum numbers in a list… >>> span([3, 1, 42, 7]) 41 >>> span([42, 42, 42, 42]) min(x, y) max(x, y) These are built into Python!

Try This... Write a python function called gauss that accepts a positive integer argument N and returns the sum 1 + 2 + … + N 2. Write a python function called sumOfSquares that accepts a positive integer N and returns the sum 12 + 22 + 32 + … + N2 When Carl Friedrich Gauss was in primary school, his teacher assigned the class to the problem of adding up the numbers 1 to 100. Gauss figured out the shortcut formula n(n+1)/2 and finished the task in a short time. The teacher punished him for “misbehavior”! You can write extra “helper” functions too!

return vs print... def dbl(x): def trbl(x): return 2 * x print 2 * x def happy(input): y = dbl(input) return y + 42 def sad(input): y = trbl(input) return y + 42 def friendly(input): y = dbl(input) print(y, "is very nice!”) return y + 42 Strings are in single or double quotes

The Alien's Life Advice Sit with a stranger at lunch …but don't steal food off their plate!