Compsci 6/101: PFTW Review how APTs and Python work, run

Slides:



Advertisements
Similar presentations
Chapter 2 Writing Simple Programs
Advertisements

CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
Python quick start guide
CIS Computer Programming Logic
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Invitation to Computer Science, Java Version, Second Edition.
Compsci 101, Fall Plan for the week: Week 2, Sept 1-5 l Understanding program structure  Defining, testing, calling functions  How to run a.
Introduction. 2COMPSCI Computer Science Fundamentals.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Compsci 101.2, Fall PFThursday l Review Organization and Problem-Solving  Defining functions, calling functions  Return types, print, None l.
Compsci 06/101, Fall What will you do in Compsci 6 Today? l Learn about selection and if/else statements  In context of solving problems  Understanding.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
Compsci 6/101, Spring More on Python, Tools, Compsci 101 l APTs, Assignments, Tools  APT: Algorithmic Problem-solving and Testing  How to get.
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
Compsci 101.2, Fall PFTWeek l Introduce new Python concepts  Control: if, elif, else, for  Data: Strings, Lists Operators on data: slicing,
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Decisions in Python Boolean functions. A Boolean function This is a function which returns a bool result (True or False). The function can certainly work.
CompSci 101 Introduction to Computer Science January 28, 2016 Prof. Rodger compsci101 spring161.
Compsci 6/101, Spring PFTW: Functions, Control, Python/Tools l How do functions work and why do we use them?  Functions we call (APIs), Functions.
Compsci 06/101, Spring Compsci 6: PFTW l Problem solving and (Python) programming  What are the steps in solving an APT?  How do you get better.
CompSci 101 Introduction to Computer Science February 4, 2016 Prof. Rodger compsci101 spring161.
CompSci 101 Introduction to Computer Science January 26, 2016 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
CompSci 101 Introduction to Computer Science Sept 13, 2016 Prof. Rodger compsci101 fall161.
Chapter 2 Writing Simple Programs
Math operations 9/19/16.
Control Structures I Chapter 3
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Based on slides by Shawn.
CompSci 101 Introduction to Computer Science
CMSC201 Computer Science I for Majors Lecture 22 – Binary (and More)
Computing and Statistical Data Analysis Lecture 2
Building Java Programs
Topics Introduction to Repetition Structures
Python: Control Structures
CompSci 101 Introduction to Computer Science
Introduction to Python and programming
Debugging and Random Numbers
Computer Programming I
CompSci 101 Introduction to Computer Science
Primitive Data, Variables, Loops (Maybe)
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Compsci 101, APTs and Sequences and Selection
CS 240 – Lecture 11 Pseudocode.
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Introduction to Python and programming
Lesson 2 Programming constructs – Algorithms – Scratch – Variables Intro.
Introduction to Python and programming
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
CompSci 101 Introduction to Computer Science
Building Java Programs
Computational Thinking for KS3
Structured Programming Taken from notes by Dr. Neil Moore
Introduction to Python and programming
Testing and Repetition
High Level Programming Languages
Boolean Expressions to Make Comparisons
SSEA Computer Science: Track A
The Data Element.
Building Java Programs
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Javascript Chapter 19 and 20 5/3/2019.
Programming with Python, for beginners
The Data Element.
Building Java Programs
Introduction to Python and programming
CompSci 101 Introduction to Computer Science
Presentation transcript:

Compsci 6/101: PFTW Review how APTs and Python work, run Good, Bad, Ugly: getting better, avoid frustration, … How do you run/test APT code, other Python code Control flow in Python Changing order in which Python statements execute Loops and if statements Essential for writing real programs Get ready for first assignment Difference between assignment and APTs?

BMI for everyone How do we get at the data in a Google form? Why would we use a Google form? Advantages of data in the cloud? Shared data? How do we find BMI for one person Must do this before we do it for 100 people What do we do about dirty data? Looping and accumulating values The programming idiom of v = v + 55 Generalized: total += value

Accumulating a value Variables in Python: name, type, value The name is a label on an "object", "box", value What does v = v + 52 do? Executing the assignment statement Evaluate expression on right hand side When done store the value of expression with label on left Can this result in changing the value of the variable? Does this change the name of the variable? Advantages of x += 1, or cool_value += 1

How to solve an APT Two very, very, very important steps How to solve the problem with Paper, Pencil, (Calculator) How to translate problem-solving to Python Both steps can be hard, vocabulary and language are initially a real barrier The more experience you have with Python, the easier step 2 will get The more you understand the idioms and power of the language the more you can let step 2 influence step 1 Step 1 is key, without it you won’t get anywhere

APT Pancake How do you solve this problem? First steps: are there simple cases that can be solved immediately? What are these for the pancake problem? How will you identify with Python? Sometimes it helps to know if you are on track, use Python to check your paper and pencil work Get specific, solve for 5, not N Fix one parameter, vary the other Identify the cases and continue

Three pancakes in a two-cake pan… Number of cakes in the system First 5 minutes Number of cakes in the system Second 5 minutes

Three pancakes in a two-cake pan… Number of cakes in the system Third 5 minutes How many minutes to cook all three pancakes?

How to teach pancake flipping http://www.youtube.com/watch?v=W_gxLKSsSIE Is this computer science? http://bit.ly/zykOrh For longer, more complex robotic tasks http://www.youtube.com/watch?v=4usoE981e7I Back to specifics: Capacity = 5 Numcakes = 1,2,…5? Numcakes = 6,7,8,9,10? Numcakes = 11,12,13,14,15? Is five special? 4? 3? 2?

Eclipse Interlude Finishing the Pancake problem Translating problem-solving ideas to code Control with if/elif: arithmetic with / and %

Lessons: special cases, abstractions There are special cases in many, many problems Identifying them is important Abstracting them away when possible is important Example: SilverDistance APT Instead of four quadrants/cases, reducible to two? Instead of (x,y) and (z,w) translate to (0,0) and (z-x,w-y) Translating ideas into (Python) code How do we create interesting “heads”, “totem poles” ? How do create software for identikit? How do we create Facebook, Foursquare, …

What years are leap years? 2000, 2004, 2008, … But not 1900, not 2100, yes 2400! Yes if divisible by 4, but not if divisible by 100 unless divisible by 400! (what?) def is_leap_year(year): if year % 400 == 0: return True if year % 100 == 0: return False if year % 4 == 0: There is more than one way to skin a cat, but we need at least one way

Python if statements and Booleans In python we have if: else: elif: Used to guard or select block of code If guard is True then, else other What type of expression used in if/elif tests? ==, <=, <, >, >=, !=, and, or, not, in Value of expression must be either True or False Type == bool, George Boole, Boolean, Examples with if String starts with vowel Rock, paper, scissors (!aka Rochambeau) winner

Grace Murray Hopper (1906-1992) “third programmer on world's first large-scale digital computer” US Navy: Admiral “It's better to show that something can be done and apologize for not asking permission, than to try to persuade the powers that be at the beginning” Craig Gentry is Duke class of 1995, then Duke Law School, then Stanford PhD in computer science ACM Hopper award given for contributions before 35 2004: Jennifer Rexford 2008: Dawson Engler 2010: Craig Gentry: http://www.youtube.com/watch?v=qe-zmHoPW30

How do you solve a problem like …? Translating English to Piglatin Why is this fascinating? http://www.google.com/webhp?hl=xx-piglatin Is this like translating English to German? Is it like translating Python to bytecode? “downplay their unique quiet strength” “ownplay-day eir-thay unique-way iet-quay ength-stray” What are the rules for pig-latin? See APT

APT Piglatin How do you solve this problem? Translation to Python First steps: are there simple cases that can be solved immediately? What are these for the piglatin problem? How will you identify with Python? Words that begin with … Vowel Foods that begin with the letter ‘q’ for 200 Alex Translation to Python First ‘q’, then vowels At this point get ready for is_vowel and starts with ‘q’. You can write code to do letter ‘q’ words and then show the is_vowel slide that comes next

Three versions of is_vowel def is_vowel(ch): if ch =='e': return True if ch == 'a': if ch == 'i': if ch == 'o': if ch == 'u': return False def is_vowel(ch): c = "aeiou".count(ch) if c > 0: return True else return False def is_vowel(ch): return "aeiou".count(ch) > 0

Piglatin, age-stay one-way def convert(s): if s[0] == 'q': return s[2:]+"-quay" if is_vowel(s[0]): return s+"-way" Preview of next lab: slicing, concatenation, index Where does string-indexing start? What does slice with a single parameter do?

Piglatin, age-stay o-tway def convert(s): if s[0] == 'q': return s[2:]+"-quay" if is_vowel(s[0]): return s+"-way" if is_vowel(s[1]): return s[1:]+"-"+s[0]+"ay" if is_vowel(s[2]): return s[2:]+"-"+s[:2]+"ay" if is_vowel(s[3]): return s[3:]+"-"+s[:3]+"ay" if is_vowel(s[4]): return s[4:]+"-"+s[:4]+"ay"

Piglatin, age-stay ee-threay def convert(s): if s[0] == 'q': return s[2:]+"-quay" if is_vowel(s[0]): return s + "-way" for index in range(1,len(s)): if is_vowel(s[index]): return s[index:]+"-"+s[:index]+"ay" Generalize/parameterize by what varies What does a loop do? it repeats!

Dawson Engler ACM Hopper Award 2008 "In his papers on automated program checking, Dawson Engler introduces and develops powerful techniques and tools for practical program analysis for finding errors in code." Started coverity.com Very successful startup to find errors in code http://myvideos.stanford.edu/player/slplayer.aspx?course=CS240&p=true