Compsci 101.2, Fall 2015 14.1 Plan for TDAFB (after fall break) l Hear via email about plans to catch-up and stay-ahead  Profs. Rodger and Astrachan to.

Slides:



Advertisements
Similar presentations
ThinkPython Ch. 10 CS104 Students o CS104 n Prof. Norman.
Advertisements

CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Introduction to Computing Science and Programming I
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Recursion Introduction to Computing Science and Programming I.
Program Design and Development
Algorithms and Efficiency of Algorithms February 4th.
Searching/Sorting Introduction to Computing Science and Programming I.
Elementary Data Structures and Algorithms
Guide to Programming with Python
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
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.
CIT 590 Intro to Programming Lecture 4. Agenda Doubts from HW1 and HW2 Main function Break, quit, exit Function argument names, scope What is modularity!
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 101.2, Fall PFThursday l Review Organization and Problem-Solving  Defining functions, calling functions  Return types, print, None l.
Q and A for Sections 2.9, 4.1 Victor Norman CS106 Fall 2015.
CompSci 101 Introduction to Computer Science Sept. 9, 2014 Prof. Rodger President Brodhead speech graduation 2010 CompSci 101 Fall
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 Introduction to Computer Science Sept 29, 2011 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not.
I Power Higher Computing Software Development High Level Language Constructs.
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.
Compsci 101.2, Fall Plan for October l Review Catchup and Midterm and Future  Make sure everyone understand options l Review Assignment.
Georgia Institute of Technology Speed part 4 Barb Ericson Georgia Institute of Technology May 2006.
8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Compsci 101.2, Fall Plan for FWON l Review current assignments and APTs  Review Dictionaries and how to use them  Code and APT walk-through.
Compsci 101.2, Fall Plan for 11/9 and 11/11 l Reviewing Concepts for test  Loops: index and by element  Strings, Lists, Sets, Dictionaries.
14. DICTIONARIES AND SETS Rocky K. C. Chang 17 November 2014 (Based on from Charles Dierbach, Introduction to Computer Science Using Python and Punch and.
Compsci 101.2, Fall Plan for October 29 l Review dictionaries and their use  Very efficient, easy to use  Efficiency doesn't matter much for.
Compsci 101.2, Fall Plan for October 22 l Images, tuples, RGB color model  Image processing by understanding API  Image processing with tuples.
Compsci 6/101, Spring WBFSB l Plan for this week  Get test back, review, look for problems/weaknesses  How to address these?  Assignments.
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
CompSci 101 Introduction to Computer Science February 4, 2016 Prof. Rodger compsci101 spring161.
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
CompSci 101 Introduction to Computer Science Feb 24, 2015 Prof. Rodger.
CompSci 6 Introduction to Computer Science Sept. 20, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science January 26, 2016 Prof. Rodger compsci 101, spring
CompSci 6 Introduction to Computer Science September 27, 2011 Prof. Rodger CompSci 6 Fall
CompSci 101 Introduction to Computer Science February 16, 2016 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
CompSci 101 Introduction to Computer Science March 8, 2016 Prof. Rodger.
Guide to Programming with Python Chapter Four Strings, and Tuples; for Loops: The Word Jumble Game.
Q and A for Sections 2.9, 4.1 Victor Norman CS106 Fall 2015.
CompSci 101 Introduction to Computer Science March 1, 2016 Prof. Rodger.
String and Lists Dr. José M. Reyes Álamo.
Intro to CS Nov 21, 2016.
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Python – May 18 Quiz Relatives of the list: Tuple Dictionary Set
Introduction to Computing Science and Programming I
CMSC201 Computer Science I for Majors Lecture 22 – Searching
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
While Loops BIS1523 – Lecture 12.
Welcome to CS 1010! Algorithmic Problem Solving.
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
CEV208 Computer Programming
String and Lists Dr. José M. Reyes Álamo.
6. Dictionaries and sets Rocky K. C. Chang 18 October 2018
CompSci 101 Introduction to Computer Science
Presentation transcript:

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 supply info l Review APTs due next week  Ideas, Code, Algorithms, approaches  Review loops and structures  How sets can be useful l Word games to start things off  Assignment coming

Compsci 101.2, Fall Succeeding with APTs in Compsci 101 l First do example, solve problem by hand, then Python  Capable of doing all examples by hand for APT You don't want to have to do *all* of them by hand! l Using built-in functions:  len(x), sorted(x), max(x), ' '.join([…])  What is return type of each, which is "it depends" l Two loops (index/element), Three structures  String, list, and now set

Compsci 101.2, Fall Computational Jumble Use this problem to think about word games l Human approach  What do you do? l Computational method?  Cheating or insight?

Compsci 101.2, Fall Eros by any other name would be sore l See Jumble.py (accessible via snarf)  Find standard or canonical form for jumbled  "aeprs" is … in alphabetical order!  sorted('spear') and sorted([3,1,2,8]) l Review of list comprehensions,  Given a large list of strings named words, what does this comprehension do? [w for w in words if len(w) == len('rose')]

Compsci 101.2, Fall How long does this take in Jumble.py? [w for w in words if sorted(w) == sorted(jword)] l Go through each of 354,984 words and …  Sort the word, which returns a list  Compare to sorted form of each word l What if we change boolean filter?  Why does this appear to make a difference? if len(w) == len(jw) and sorted(w) == sorted(jw)

Compsci 101.2, Fall Jumble programming concepts l When you run the program it starts in __main__  This is how Python works, boilerplate code l What's the variable words at beginning?  Global variable. Accessible in every function in the Python module  Used sparingly can be useful in a small module  Abused, can lead to hard to maintain code

Compsci 101.2, Fall Answer Questions After questions, solving APTs: ideas and hints for making progress

Compsci 101.2, Fall ColorfulTiles: Ideas, Algorithm, Code l "RGGBBBRYYB" has solution 3, why? l Indexing can help. Changing a cell's color?  What about tile at i-1 and at i+1 (from i )  Change cell 2? Change 3, 4, 5?

Compsci 101.2, Fall Two structures, two types of loop l Loop by index or by element?  What do we do with each element, how to compare to element before? Or After?  Can do with either loop, much simpler with indexing loop!

Compsci 101.2, Fall Two structures, two types of a loop l What structure to use: string or list?  After examining each element, operations?  At green, with green to left, change me to ____ ? Use list to mark with '*', advantage of four colors! Remember strings are immutable

Compsci 101.2, Fall Solving UniqueNames APT

Compsci 101.2, Fall Approach to solving APT l Loop over classes, find name/year, repeat  Indexing loop? name/year, name/year, …  Use range(x,y,2) for accessing every other entry l Add all student names to a list or a set  How to make list contain no duplicates? Set  How to sort all the names? Sorted l Combine ideas, and done!

Compsci 101.2, Fall Coding aspects, not algorithmic Given list of names…stored in taken … l Add a name to list or set, differences?  taken.append(name) or taken.add(name) l Create a list of just the unique names?  uniq = list(set(taken)) l Create a sorted version of taken?  st = sorted(taken) -- list, string, or set ? l Create space-separated string with values?  ' '.join(joinable) what type is joinable?

Compsci 101.2, Fall Challenge APT UniqueZoo l Using sets and set operations can help  Set intersection and set union  Other set operations l A | B, set union, A & B, set intersection l B – A, set difference, B ^ A, symmetric diff

Compsci 101.2, Fall Nested Loops: FortunateNumbers l How to loop over all characters in each string of a list, e.g., to count all occurrences?  Looping over string in loop over list…  Think only about inner loop first, … l Often useful to put inner loop in another function! Did this in Caesar.py for x in ['apple', 'pear', 'orange']: for ch in x: print ch values[alpha.index(ch)] += 1

Compsci 101.2, Fall Create "couples" from two lists A, B l A name is fixed as the inner loop executes  See output to reinforce this idea A = ['sam', 'lou', 'chris'] B = ['terry', 'brook',, 'val'] for aname in A: for bname in B: print aname,",",bname sam, terry sam, brook sam, val lou, terry lou, brook lou, val chris, terry chris, brook chris, val

Compsci 101.2, Fall Answer Questions

Compsci 101.2, Fall Sets are unique and fast! Consider importance of -- if x in Y:  How long does it take to find x in Y?  What does it depend on? See Timings.py l How can we find if a book is in library?  Assume all books shelved properly, then …  If we can't assume that, what do we do? l Look up in set doesn't depend on set size!  Cannotadd list to set or set to set or …