Compsci 101.2, Fall 2015 6.1 PFThursday l Review Organization and Problem-Solving  Defining functions, calling functions  Return types, print, None l.

Slides:



Advertisements
Similar presentations
A8 – Control Structures if, if-else, switch Control of flow in Java Any sort of complex program must have some ability to control flow.
Advertisements

I210 review Fall 2011, IUB. Python is High-level programming –High-level versus machine language Interpreted Language –Interpreted versus compiled 2.
Programming with Collections Grouping & Looping - Collections and Iteration Week 7.
Python Control of Flow.
1 CSC 221: Introduction to Programming Fall 2012 course overview  What did you set out to learn?  What did you actually learn?  Where do you go from.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Lists in Python.
AS Computing Introduction to Programming. What is a Computer Program? A list of instructions that a computer must work through, in a logical sequence,
ICAPRG301A Week 4Buggy Programming ICAPRG301A Apply introductory programming techniques Program Bugs US Navy Admiral Grace Hopper is often credited with.
Compsci 06/101, Fall Compsci 6/101: Sept 6-10 l We've looked at the language Python  Names and types: int, float, long, String, file, …  Operations:
Compsci 101.2, Fall PFTT (plan for this Thursday) l What is a Python program?  In the context of what we do in Compsci 101  In a neuroscience.
Compsci 06/101, Fall Compsci 6/101: Random debugging?!# l The joys and rewards of writing code to solve a problem  How do we know where to begin?
Fall Week 4 CSCI-141 Scott C. Johnson.  Computers can process text as well as numbers ◦ Example: a news agency might want to find all the articles.
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 06/101, Fall How to build a program l Create a module  Can be used by other modules via import  Collection of functions, later collection.
Compsci 6/101, Spring More on Python, Tools, Compsci 101 l APTs, Assignments, Tools  APT: Algorithmic Problem-solving and Testing  How to get.
Compsci 6/101, Spring PFTW: Sequences aka Strings&Lists l From Return values to Random-ness [aka two R's]  What power does random provide? 
Compsci 101.2, Fall PFTheWeek 9/21-9/25 l Potpourri, Hodgepodge of Review Concepts  File reading and writing  Boolean expressions  Arithmetic.
Python Mini-Course University of Oklahoma Department of Psychology Day 2 – Lesson 7 Conditionals and Loops 4/18/09 Python Mini-Course: Day 2 - Lesson 7.
Compsci 101.2, Fall PFTWeek l Introduce new Python concepts  Control: if, elif, else, for  Data: Strings, Lists Operators on data: slicing,
Compsci 06/101, Fall Vocabulary l What's the Spanish word for 'boy'? 'eat'?  How do you know? l What about the Turkish equivalents?  How do.
Compsci 101.2, Fall #TBT l Finish some Python concepts and questions from earlier  Review for midterm exam l Strategies for success in 101 assignments.
Compsci 101.2, Fall Plan for FFWOO l Programming in the small and in the large  Making one function work correctly, especially in the context.
Introduction to Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Compsci 101.2, Fall Plan for TDAFB (after fall break) l Hear via about plans to catch-up and stay-ahead  Profs. Rodger and Astrachan to.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
CompSci 101 Introduction to Computer Science January 28, 2016 Prof. Rodger compsci101 spring161.
Compsci 101.2, Fall Plan for WEFWOO l Review for exam, studying and practicing for exams and APTs in Compsci 101  Why memorization doesn't help.
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.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
CompSci 101 Introduction to Computer Science February 4, 2016 Prof. Rodger compsci101 spring161.
CompSci 101 Introduction to Computer Science February 11, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science January 26, 2016 Prof. Rodger compsci 101, spring
Design A software design specifies how a program will accomplish its requirements A design includes one or more algorithms to accomplish its goal.
CPS 100, Spring Interlude for trees l Joyce Kilmer Joyce Kilmer l Balanced Trees  Splay  Red-Black  AVL  B-tree.
CompSci 101 Introduction to Computer Science Sept 13, 2016 Prof. Rodger compsci101 fall161.
The need for Programming Languages
CompSci 101 Introduction to Computer Science
Algorithmic complexity: Speed of algorithms
Python: Control Structures
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Compsci 6/101: PFTW What is Python? What is a programming language?
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Incrementing ITP © Ron Poet Lecture 8.
Python - Loops and Iteration
Compsci 101, APTs and Sequences and Selection
CompSci 101 Introduction to Computer Science
Introduction to Computer Science
Structured Programming Taken from notes by Dr. Neil Moore
CEV208 Computer Programming
Algorithmic complexity: Speed of algorithms
Compsci 6/101: PFTW Review how APTs and Python work, run
functions: argument, return value
Intro to Computer Science Loops
Algorithmic complexity: Speed of algorithms
Introduction to Computer Science
Introduction to Strings
Introduction to Computer Science
Class code for pythonroom.com cchsp2cs
Introduction to Strings
3.0 - Design A software design specifies how a program will accomplish its requirements A design includes one or more algorithms to accomplish its goal.
CompSci 101 Introduction to Computer Science
Presentation transcript:

Compsci 101.2, Fall PFThursday l Review Organization and Problem-Solving  Defining functions, calling functions  Return types, print, None l Incremental construction as design pattern  Build programs: start small, add with confidence  Build new strings: append/concatenate values  Build lists (later, but similar to strings)

Compsci 101.2, Fall APT Pancake: l How do you solve this problem?  If you have confidence you can solve for any size pan, then start programming  If you can't do it by hand … Get some credit for APT, some dancing! l Sometimes APTs have hard algorithms  Translating to code not so bad l Sometimes APTs have easy algorthms  Translating to code is difficult

Compsci 101.2, Fall Three pancakes in a two-cake pan… l Number of cakes in the system  First 5 minutes l Number of cakes in the system  Second 5 minutes

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

Compsci 101.2, Fall Methodically by hand, small values l Pan has capacity 8, vary #pancakes  Can you cook 11 in 15 minutes? Why?  Can you cook 13 in 15 minutes? Why? cakes time10 ?

Compsci 101.2, Fall Methodically by hand, small values l Pan has capacity 8, vary #pancakes cakes time

Compsci 101.2, Fall Methodically by hand, small values l Pan has capacity 8, vary #pancakes cakes time

Compsci 101.2, Fall Methodically by hand, small values l Pan has capacity 8, vary #pancakes cakes time

Compsci 101.2, Fall Pancake Algorithm l If you have pan of size 17 and 34 pancakes l If you have pan of size 17 and 43 pancakes l Pan fits 100 pancakes, but you have 452 l Pan fits N pancakes, but you have P  if P <= N then time needed is …  X = P/N, what does this mean for time?  Y = P % N, what does this mean for time?

Compsci 101.2, Fall Eclipse Interlude l Finishing the Pancake problem  Translating problem-solving ideas to code  Control with if/elif: arithmetic with / and %

Compsci 101.2, Fall Algorithmic Problem/Program Testing l Complete this form for two more APTs

Compsci 101.2, Fall How to teach pancake flipping l  Is this computer science?  For longer, more complex robotic tasks l Do robots matter?  Do they dream?  Self-driving cars?  Machine learning?

Compsci 101.2, Fall Three versions of is_vowel def is_vowel(ch): if ch =='e': return True if ch == 'a': return True if ch == 'i': return True if ch == 'o': return True if ch == 'u': return True 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

Compsci 101.2, Fall Python if statements and Booleans l In python we have if: else: elif:  Used to guard or select block of code  If guard is True then, else other l 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, l Examples with if  String starts with vowel (useful for APT Emphasize)

Compsci 101.2, Fall Eclipse Interlude l Finishing Emphasize  Identifying vowels  Helper functions  Slicing strings

Compsci 101.2, Fall Software Dreams l Translating ideas into (Python) code  Create interesting “heads”, “totem poles” ?  Create software for face recognition? Gait?  Create "five four" from "four five"?  Create "SCUBA" from "self contained underwater breathing apparatus" l Master the syntax of the language?  Organization of program constructs  Knowledge of libraries  Practice and experience!

Compsci 101.2, Fall Building Totem in stages/incrementally l What functions do not return values?  They print strings returned by other functions l For totem and randompole, which one first?  Don't do both at same time, grow the program l Start simple  Next?  Add?  Questions? def hair_part(): return "xxyyzz" def eye_crossed(): return "123456" def totem(): print hair_part() print eye_crossed()

Compsci 101.2, Fall Anatomy of a Python String l String is a sequence of characters  Functions we can apply to sequences: len, slice [:], others  Methods applied to strings [specific to strings] st.split(), st.startswith(), st.strip(), st.lower(), … st.find(), st.count() l Strings are immutable sequences  Characters are actually length-one strings  Cannot change a string, can only create new one What does upper do?  See resources for functions/methods on strings l Iterable : Can loop over it, Indexable : can slice it

Compsci 101.2, Fall Lynn Conway See Wikipedia and lynnconway.com l Joined Xerox Parc in 1973  Revolutionized VLSI design with Carver Mead l Joined U. Michigan 1985  Professor and Dean, retired '98 l NAE '89, IEEE Pioneer '09 l Helped invent dynamic scheduling early '60s IBM l Transgender, fired in '68

Compsci 101.2, Fall Incremental + : numbers and strings l Wtht vwls cn y stll rd ths sntnce?  Create a no-vowel version of word  Examine each character, if it's not a vowel …  Pattern of building a string def noVowels(word): ret = "" for ch in word: if ! is_vowel(ch): ret = ret + ch return ret

Compsci 101.2, Fall Counting vowels in a string l Accumulating a count in an int is similar to accumulating characters in a string Alternative version of adding: value += 1 def vowelCount(word): value = 0 for ch in word: if is_vowel(ch): value = value + 1 return value

Compsci 101.2, Fall From high- to low-level Python def reverse(s): r = "" for ch in s: r = ch + r return r l Create version on the right using dissassembler dis.dis(code.py) 7 0 LOAD_CONST 1 ('') 3 STORE_FAST 1 (r) 8 6 SETUP_LOOP 24 (to 33) 9 LOAD_FAST 0 (s) 12 GET_ITER >> 13 FOR_ITER 16 (to 32) 16 STORE_FAST 2 (ch) 9 19 LOAD_FAST 2 (ch) 22 LOAD_FAST 1 (r) 25 BINARY_ADD 26 STORE_FAST 1 (r) 29 JUMP_ABSOLUTE 13 >> 32 POP_BLOCK 10 >> 33 LOAD_FAST 1 (r) 36 RETURN_VALUE

Compsci 101.2, Fall Bug and Debug l software 'bug' software 'bug' l Start small  Easier to cope l Judicious 'print'  Debugger too l Verify the approach being taken, test small, test frequently  How do you 'prove' your code works?