Plan For the Week. Solve problems by programming in Python. Compsci 101 Way-of-life. Vocabulary and Concepts

Similar documents
BMI for everyone. Compsci 6/101: PFTW. Accumulating a value. How to solve an APT. Review how APTs and Python work, run

Chapter 8: Recursion

Compsci 290.3, Spring 2017 Software Design and Implementation: Mobile Landon Cox Owen Astrachan

TAFTW (Take Aways for the Week) APT Quiz and Markov Overview. Comparing objects and tradeoffs. From Comparable to TreeMap/Sort

DevOps Course Content

LobbyView: Firm-level Lobbying & Congressional Bills Database

Hoboken Public Schools. PLTW Introduction to Computer Science Curriculum

Congress Lobbying Database: Documentation and Usage

Data 100. Lecture 9: Scraping Web Technologies. Slides by: Joseph E. Gonzalez, Deb Nolan

Areeq Chowdhury: Yeah, could you speak a little bit louder? I just didn't hear the last part of that question.

Fairsail Payflow Cookbook for CSV Record Downloads

Hoboken Public Schools. Project Lead The Way Curriculum Grade 8

Technology. Technology 7-1

Review: Background on Bits. PFTD: What is Computer Science? Scale and Bits: Binary Digits. BIT: Binary Digit. Understanding scale, what does it mean?

Case: 1:16-cv Document #: 586 Filed: 01/03/18 Page 1 of 10 PageID #:10007 FOR THE NORTHERN DISTRICT OF ILLINOIS EASTERN DIVISION

Coverage tools Eclipse Debugger Object-oriented Design Principles. Oct 26, 2016 Sprenkle - CSCI209 1

IBM Cognos Open Mic Cognos Analytics 11 Part nd June, IBM Corporation

Let the Blogging Begin!

ForeScout Extended Module for McAfee epolicy Orchestrator

30 Transformational Design with Essential Aspect Decomposition: Model-Driven Architecture (MDA)

Aspect Decomposition: Model-Driven Architecture (MDA) 30 Transformational Design with Essential. References. Ø Optional: Ø Obligatory:

Google feud unblocked

30 Transformational Design with Essential Aspect Decomposition: Model-Driven Architecture (MDA)

Installation Guide: cpanel Plugin

Yes, my name's Priit, head of the Estonian State Election Office. Right. So how secure is Estonia's online voting system?

Module 2 Legal Infrastructure

This Week on developerworks: Ruby, AIX, collaboration, BPM, Blogger API Episode date:

Probabilistic Latent Semantic Analysis Hofmann (1999)

Lecture 8: Verification and Validation

31) Feature Models and MDA for Product Lines

Economic and Social Council

GOOFY COVERS GOVERNMrnNT. Recommended for ages GET READY!

Clause Logic Service User Interface User Manual

Hoboken Public Schools. AP Statistics Curriculum

Drafting Legislation Using XML in the U.S. House of Representatives

Programming with Android: SDK install and initial setup. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Lab 11: Pair Programming. Review: Pair Programming Roles

OPEN SOURCE CRYPTOCURRENCY

>> OUR NEXT CASE OF THE DAY IS DEBRA LAFAVE VERSUS STATE OF FLORIDA. >> YOU MAY PROCEED. >> MAY IT PLEASE THE COURT. I'M JULIUS AULISIO.

Google App Engine 8/10/17. CS Cloud Compu5ng Systems--Summer II 2017

Cloud Tutorial: AWS IoT. TA for class CSE 521S, Fall, Jan/18/2018 Haoran Li

The Free State Foundation's TENTH ANNUAL TELECOM POLICY CONFERENCE

One View Watchlists Implementation Guide Release 9.2

- 1 - End-User License Agreement

FM Legacy Converter User Guide

Jussi T. Lindgren, PhD Lead Engineer Inria

Using Appointment Slots

(Non-legislative acts) DECISIONS

Fall 2016 COP 3223H Program #5: Election Season Nears an End Due date: Please consult WebCourses for your section

Clauses: Building Blocks for Sentences

Case 2:03-cv DGC Document 141 Filed 01/04/2006 Page 1 of 32

A Brief Synopsis of How ESTA's Technical Standards Program Works

Non-fiction: Winning the Vote

Section 2. Obtaining a Patent: The Four Basic Steps. Chapter 10. Step Three: Estimate Application Costs

ALL I EVER WROTE: THE COMPLETE WORKS OF RONNIE BARKER DOWNLOAD EBOOK : ALL I EVER WROTE: THE COMPLETE WORKS OF RONNIE BARKER PDF

Objec&ves. Review. So-ware Quality Metrics Sta&c Analysis Tools Refactoring for Extensibility

English as a Second Language Podcast ESL Podcast Legal Problems

UN/CEFACT Cross Industry Invoice (CII) and related UN/CEFACT work CEF einvoicing Event

FROM THE KORTE WARTMAN LAW FIRM. Page: 1 IN THE FIFTEENTH JUDICIAL CIRCUIT COURT IN AND FOR PALM BEACH COUNTY, FLORIDA CASE NO CA (AW)

James V. Crosby, Jr. v. Johnny Bolden

A NOVEL EFFICIENT REVIEW REPORT ON GOOGLE S PAGE RANK ALGORITHM

Overview. Ø Neural Networks are considered black-box models Ø They are complex and do not provide much insight into variable relationships

CONSIDERATION OF SENATE BILL 14 1/25/2011. through and telling them, "Any Mexican-American citizen

11/15/13. Objectives. Review. Our Screen Saver Dependencies. Our Screen Saver Dependencies. Project Deliverables Timeline TEAM FINAL PROJECT

Hoboken Public Schools. Algebra II Honors Curriculum

Search Trees. Chapter 10. CSE 2011 Prof. J. Elder Last Updated: :51 PM

OSS-Lizenzinformationen K6. Open Source Lizenzinformationen für Terminal 9620-K6 und 9720-K6

Review of Lab 9. Review Lab 9. Social Network Classes/Driver Data. Lab 10 Design

MSC TRUSTGATE.COM SDN BHD LICENSE AGREEMENT FOR SYMANTEC SECURED SEAL

IPO Standing IP Committee Policy Manual

PRESS BRIEFING BY JOHN SCHMIDT, ASSOCIATE ATTORNEY GENERAL, DEPARTMENT OF JUSTICE,

Appeals: First-tier Tribunal

New features in Oracle 11g for PL/SQL code tuning.

Agreement for iseries and AS/400 System Restore Test Service

Introduction: Data & measurement

The Other America: Poverty In The United States By Michael Harrington READ ONLINE

UCSC GENOME BROWSER INTERNAL USE LICENSE

Case 3:15-cv HEH-RCY Document Filed 02/05/16 Page 1 of 6 PageID# Exhibit D

The Pupitre System: A desk news system for the Parliamentary Meeting rooms

Technology Tuesday Webcast Series: Want To Go Blogging? March 9, 2004 Presenter: Lori Bowen Ayre

Want To Go Blogging? Agenda. Bloggers. Residents of Planet Blogistan or Web + Logs

Review: SoBware Development

Journal of Statistical Software

Newark City Schools Strategic Plan

Apache Tomcat was obtained from the Apache Software Foundation under various licenses

Gibbs makes it semi-official: Obama 'likely' to seek re-

Experimental Computational Philosophy: shedding new lights on (old) philosophical debates

Downloaded from: justpaste.it/vlxf

STATE OF NEW MEXICO COUNTY OF DONA ANA THIRD JUDICIAL DISTRICT CV WILLIAM TURNER, Plaintiff, vs.

A Skeleton-Based Model for Promoting Coherence Among Sentences in Narrative Story Generation

PRINT an answer sheet (page 4).

The tool of thought for software solutions

Voting System Qualification Test Report Democracy Live, LiveBallot Version 1.9.1

Joint SO/AC Working Group (WG) Charter

Question 1. Does your library plan to remain in the Federal Depository Library Program?

- web-app_3_1.xsd - web-common_3_1.xsd - web-fragment_3_1.xsd may be obtained from:

Management Overview. Introduction

>>> THE SECOND CASE IS GRIDINE V. THE STATE OF FLORIDA. YOU MAY PROCEED. >> MAY IT PLEASE THE COURT, I'M GAIL ANDERSON REPRESENTING MR.

SAMPLE. Disclaimer: This sample completed form does not necessarily cover all scenarios that are catered for by the form. Western Cape / Wes-Kaap

OPEN SOURCE CRYPTOCURRENCY E-PUB

Transcription:

Plan For the Week Solve problems by programming in Python Ø Like to do "real-world" problems, but we're very new to the language Ø Learn the syntax and semantics of simple Python programs Compsci 101 Way-of-life Ø Assignments, APTs, READMEs, oh-my Vocabulary and Concepts Ø Talk, think, speak like a Compsci 101 student Ø Talk, think, speak like a computer scientist? Compsci 101.2, Fall 2015 3.1

PFTDay (introducing the week) Review Python program we didn't get to Ø helloaroundtheworld.py Ø Forming hypotheses about programs and Python, testing hypotheses by running code Functions in Python and Compsci101 Ø What is a function, organizing programs Ø How do we gain understanding and practice with Python functions in Compsci101 Compsci 101.2, Fall 2015 3.2

Understanding terminology: code Move from "Hello World" to "Hello Around the World" Ø Look at Python, code, libraries Ø Learning (reviewing) terminology about Python print "hello world" f = open("hello_unicode.txt") for line in f: print line) Compsci 101.2, Fall 2015 3.3

Running and Understanding Code Need Python compiler/interpreter Ø We're using Canopy, includes libraries Need an editor development environment Ø We use Eclipse and PyDev, open source and widely used, Ambient is Duke Plugin You need experience thinking and coding and debugging ideas and code: Ø Installing the suite of tools can be cumbersome Persist, Perservere, Get Help, start over L Compsci 101.2, Fall 2015 3.4

Code Dissection Every line thought about, occasionally understood at different levels Ø Use your understanding of natural language and experience, apply to Python f = open("hello_unicode.txt") Ø Run program and apply knowledge to each of the other lines f = open("hello_unicode.txt") for line in f: print line Compsci 101.2, Fall 2015 3.5

Questions about Python Code Every line thought about, occasionally understood Ø What about when you make changes to the program? Answer these questions about possible errors introduced when making changes http://bit.ly/101fall15-827-3 Compsci 101.2, Fall 2015 3.6

Barbara Liskov (one of) first women to earn PhD from compsci dept Ø Stanford 1968 Turing award in 2008 Ø Programming Languages It's much better to go for the thing that's exciting. But the question of how you know what's worth working on and what's not separates someone who's going to be really good at research and someone who's not. There's no prescription. It comes from your own intuition and judgment. Compsci 101.2, Fall 2015 3.7

Hello Around the World in Python We open a file, and we open a URL Ø Syntax slightly different, concept is similar Ø Real-world differences between files and URLs? f = open("hello_unicode.txt") f = urllib2.urlopen("http://nytimes.com") Must adhere to syntactic rules of Python Ø Naming, whitespace, : or. or ( or ) or [ or ] Must adhere to semantic rules of Python Ø Can't loop over anything, more rules to follow Compsci 101.2, Fall 2015 3.8

Libraries, Modules, APIs We need libraries of useful code Ø Ø Ø Ø Ø Can't write it all from scratch Connect to web Payment systems Mapping systems Geolocation Application Programming Interface Ø Ø How to "connect" to software Syntax and semantics of use Compsci 101.2, Fall 2015 3.9

Python programming You write a Python program Ø Starting from scratch, snarfing, finding online Ø You execute it using a Python interpreter Ø Code executes top-to-bottom, see Hello World Constructing a Python program Ø Like constructing sentences in a new language Ø Learning and using vocabulary Ø Constructing increasingly complex programs, but starting from something simple Compsci 101.2, Fall 2015 3.10

Examples of functions Compsci 101.2, Fall 2015 3.11

Functions explained In a calculator, sqrt: number in -> number out Ø What is domain, what is range? In MSWord, word count: document -> number Ø Domain is word doc, range is integer In browser, web: URL -> HTML formatted "page" Ø Domain is valid URL, range is HTML resources In Python we see similar structure! Compsci 101.2, Fall 2015 3.12

Python Functions Answer these questions based on thinking, don't run any code Ø http://bit.ly/101fall15-901-1 Why do we need functions? Ø Manage complexity of large programs Ø Test and develop code independently Ø Reuse code in new contexts: create APIs! Compsci 101.2, Fall 2015 3.13

Functions return values Most functions return values Ø Sometimes used to make things simpler, but returning values is a good idea def inch2centi(inches): return 2.54*inches xh = inch2centi(72) def pluralize(word): return word + "es" pf = pluralize("fish") Compsci 101.2, Fall 2015 3.14

What is an APT? BMI APT Automated/Algorithmic Problem Testing Ø Write one function, 2-30 lines, solve a problem Ø Tested automagically in the browser Ø Test test test Quality of code not an issue Start simple, build toward more complex Ø What is a function? A function call? Ø What is a parameter? Argument? Ø How do you run/execute a program Compsci 101.2, Fall 2015 3.15

How to solve an APT Two very, very, very important steps 1. How to solve the problem without computer Paper, Pencil, (Calculator) 2. How to translate problem-solving to Python Both steps can be hard, vocabulary and language are initially a real barrier Ø More Python experience, easier step 2 becomes Ø With experience, step 2 can influence step 1 Step 1 is key, without it you won t get anywhere Compsci 101.2, Fall 2015 3.16

Functions: BMI (Body Mass Index) What is formula? How to use it? Ø Functions allow us to re-use the formula Make sure units are correct, formula right Ø What if we want to validate data? Ø What if we want to notify folks who might need guidance? def bmi(weight, height): return 703.07 * weight/(height*height) if bmi(170,72) < 18.5: print "underweight" call replaced by return value, why use function? Compsci 101.2, Fall 2015 3.17

What does return statement do? Programs execute one line at a time Ø After one statement finishes, the next executes Ø Calling a function causes its code to execute What happens in the code that calls the function? The value returned replaces the function call Ø print math.sqrt(25.0) Ø if bmi(170,72) < 18.5: print "underweight" What if nothing returned? Ø None by default in Python Compsci 101.2, Fall 2015 3.18

Toward creating functions New meets old Ø https://www.youtube.com/watch?v=0lm-nyn06ra Old MacDonald had a farm, Ee-igh, Ee-igh, oh! And on his farm he had a pig, Ee-igh, Ee-igh, oh! With a oink oink here And a oink oink there Here a oink there a oink everywhere a oink oink Old MacDonald had a farm, Ee-igh, Ee-igh, oh! Compsci 101.2, Fall 2015 3.19

Creating Parameterized Function What differs? Variable or Parameter Old MacDonald had a farm, Ee-igh, Ee-igh, oh! And on his farm he had a horse, Ee-igh, Ee-igh, oh! With a neigh neigh here And a neigh neigh there Here a neigh there a neigh everywhere a neigh neigh Old MacDonald had a farm, Ee-igh, Ee-igh, oh! Old MacDonald had a farm, Ee-igh, Ee-igh, oh! And on his farm he had a pig, Ee-igh, Ee-igh, oh! With a oink oink here And a oink oink there Here a oink there a oink everywhere a oink oink Old MacDonald had a farm, Ee-igh, Ee-igh, oh! Compsci 101.2, Fall 2015 3.20

Abstracting over code: functions http://goo.gl/dfcpgi See snarf for class work as well These functions do not return values, they print Ø Illustrates problem decomposition, but Ø Normally have each function return a value Ø Normally use the return value in function call Compsci 101.2, Fall 2015 3.21

Part of http://goo.gl/dfcpgi (and snarf) def eieio(): print "Ee-igh, Ee-igh, oh!" def refrain(): print "Old MacDonald had a farm,", eieio() def had_a(animal): Lots of commas print "And on his farm he had a",animal,",", eieio() Compsci 101.2, Fall 2015 3.22

Anatomy and Dissection of Print Print generates output to a console, window, Ø Depends on how program invoked Ø Basically used for: help with debugging and creating output for copy/paste, view print "hello,",x,"what's up",y Space inserted between comma-separated items Ø Can use string concatentation, "hello"+str(x) Ø If statement ends with comma, no newline Ø Print anything that has a string representation Compsci 101.2, Fall 2015 3.23

Tracing program execution The def statement defines a function Ø Creates a name that can be used in program Ø Name encapsulates program statements, creates its own environment for running code Variables, parameters, local to the function Function name and statements part of Python execution environment Ø Can call or invoke the function Ø If parameters needed, must pass values for each Ø Visualize program execution: PythonTutor, brain Compsci 101.2, Fall 2015 3.24

Abstraction over barnyards In OldMacPrint we have pig() and fox() Ø What's the same in these? What's different? Ø Capture differences in parameters/variables Create new function: Ø def verse(animal, noise) Look at pig() and fox() create new function Ø Call: verse("horse", "neigh") Ø Call: verse("cow", "moo") http://bit.ly/101fall15-901-2 Compsci 101.2, Fall 2015 3.25

Nathan Myhrvold Who is he? http://bit.ly/myhrvold We invent for fun. Invention is a lot of fun to do. And we also invent for profit. The two are related because the profit actually takes long enough that, if it isn't fun you wouldn't have the time to do it. Ø http://bit.ly/zwlqxn Compsci 101.2, Fall 2015 3.26