CompSci 101 Introduction to Computer Science

Slides:



Advertisements
Similar presentations
CompSci 101 Introduction to Computer Science February 3, 2015 Prof. Rodger Lecture given by Elizabeth Dowd.
Advertisements

CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
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 6 Introduction to Computer Science October 20, 2011 Prof. Rodger.
Tips: To change your picture, click “Insert” –> “Picture”, select picture from your computer. You can adjust your picture by click the “Format” menu. When.
Built-in Data Structures in Python An Introduction.
CompSci 101 Introduction to Computer Science Sept. 9, 2014 Prof. Rodger President Brodhead speech graduation 2010 CompSci 101 Fall
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.
CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151.
Compsci 101.2, Fall Plan for October l Review Catchup and Midterm and Future  Make sure everyone understand options l Review Assignment.
CompSci 6 Introduction to Computer Science September 13, 2011 Prof. Rodger.
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.
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.
CompSci 101 Introduction to Computer Science February 10, 2015 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
Compsci 101.2, Fall Plan for October 22 l Images, tuples, RGB color model  Image processing by understanding API  Image processing with tuples.
CompSci 101 Introduction to Computer Science February 4, 2016 Prof. Rodger compsci101 spring161.
CompSci 101 Introduction to Computer Science Feb 24, 2015 Prof. Rodger.
CompSci 101 Introduction to Computer Science January 26, 2016 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science November 11, 2014 Prof. Rodger CompSci 101 Fall Review for exam.
CompSci 101 Introduction to Computer Science March 17, 2015 Prof. Rodger compsci 101, spring
CompSci 101 Introduction to Computer Science January 15, 2015 Prof. Rodger 1.
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.
CompSci 101 Introduction to Computer Science March 8, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 1, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 29, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
CompSci 101 Introduction to Computer Science Sept 13, 2016 Prof. Rodger compsci101 fall161.
CompSci 4 Java 1 Apr 2, 2009 Prof. Susan Rodger. Announcements Assignment 7 questions? –Beware having two events that kick in at the same time! –Beware.
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
CompSci 6 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
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
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Introduction to Computer Science
CISC101 Reminders Slides have changed from those posted last night…
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CISC101 Reminders Quiz 2 graded. Assn 2 sample solution is posted.
CISC101 Reminders Quiz 1 grading underway Next Quiz, next week.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CS1110 Today: collections.
Introduction to Computer Science
Introduction to Computer Science
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Course A201: Introduction to Programming
CompSci 101 Introduction to Computer Science
Presentation transcript:

CompSci 101 Introduction to Computer Science Oct. 27, 2016 Prof. Rodger compsci101 fall16

Announcements Next Reading and RQ due Nov 1 Assignment 5 due today Next Assignment out next week APT 6 due Tues Today: Review nested loops, tuple generators Focus on problem solving with sets compsci101 fall16

Review from last time: generator im.getdata(), accessing pixels Returns something like a list Use: for pix in im.getdata(): Generates pixels on-the-fly, can't slice or index unless you use list(im.getdata()) Structure is called a Python generator! Saves on storing all pixels in memory if only accessed one-at-a-time Did this example (see next slide) last time console with x = [2*n for n in range(10000)] and y = (2*n for n in range(10000)) Print them, do sum, do len on x and y and loop over them Maybe a bitly form on this topic? compsci101 fall16

Review from last time Making Tuples and Generators Overuse and abuse of parentheses To create a tuple, use parentheses To create a generator use parentheses as though creating a list comprehension! See this in PyDev console for pix in im.getdata(): (r,g,b) = pix npx = (255-r,255-g,255-b) Show tuples and generators in pydev console, using len(x) for each and seeing it fail on generator, and using loopover each and see that succeed. See file on examples [2*n for n in range(10000)] (2*n for n in range(10000))

Set Operations from pictures bit.ly/101f16-1027-1 Question: Which operation does the red represent? A) D) C) B) Answers below http://en.wikipedia.org/wiki/File:Venn0111.svg Symmetric Difference B) intersection C) everything not in either set D) Union e) Difference E) compsci101 fall16

Problems – snarf setExample.py Given a list of strings that have the name of a course (one word), followed by last names (one word each) of people in the course: Find total number of people taking any course Find number of people taking just one course ["econ101 Abroms Curtson Williams Smith”, "history230 Black Wrigley Smith”, … ] Process data – create lists of strings of names for each course Do we need the course names to answer these questions? No. We need to keep the students in a course together to represent a course, but we don’t need the names of the courses to answer these questions. compsci101 fall16

Data for example TO easier format to work with: [“compsci101 Smith Ye Li Lin Abroms Black“, “math101 Green Wei Lin Williams DeLong Noell Ye Smith”, “econ101 Abroms Curtson Williams Smith”, “french1 Wills Wrigley Olson Lee”, "history230 Black Wrigley Smith” ] TO easier format to work with: [ [ ‘Smith’, ‘Ye’, ‘Li’, ‘Lin’, ‘Abroms’, ‘Black’], [‘Green’, ‘Wei’, ‘Lin’, ‘Williams’, ‘DeLong’, ‘Noell’, ‘Ye’, ‘Smith’], [‘Abroms’, ‘Curtson’, ‘Williams’, ‘Smith’], …. ] compsci101 fall16

COMPSCI101 Set Picture of Data ECON101 Li Abroms Curtson Williams Ye MATH101 Smith Lin Noell Green Wei Delong Yavatkar Black Visual way to look at this example. Look at Smith – in four courses. Wrigley in two courses Wrigley FRENCH1 Wills HISTORY230 Lee Olson compsci101 fall16

COMPSCI101 People in CompSci 101 ECON101 Li Abroms Curtson Williams Ye MATH101 Smith Lin Noell Green Wei Delong Yavatkar Black Wrigley FRENCH1 Wills HISTORY230 Lee Olson compsci101 fall16

People Taking both Math And CompSci COMPSCI101 ECON101 Li Abroms Curtson Williams Ye MATH101 Smith Lin Noell Green Wei Delong Intersection Yavatkar Black Intersection is the green Wrigley FRENCH1 Wills HISTORY230 Lee Olson compsci101 fall16

Part 1 – processList bit.ly/101f16-1027-2 Given a list of strings that have the name of a course (one word), followed by last names of people in the course: Convert list into lists of strings of names for each course ["econ101 Abroms Curtson Williams Smith", "history230 Black Wrigley Smith", … ] [ [‘Abroms’, ‘Curtson’, ‘Williams’, ‘Smith’], [‘Black’, ‘Wrigley’, ‘Smith’, …] ] compsci101 fall16

Part 2 – peopleTakingCourses bit.ly/101f16-1027-3 Given a list of lists of names, each list represents the people in one course: Find total number of people taking any course peopleTakingCourses should return unique list of names Small Example [[‘Abroms’, ‘Curtson’, ‘Williams’, ‘Smith’], [‘Black’, ‘Wrigley’, ‘Smith’]] Answer is 6 unique names compsci101 fall16

COMPSCI101 People taking Courses - Union ECON101 Li Abroms Curtson Williams Ye MATH101 Smith Lin Noell Green Wei Delong Yavatkar Black Total Number Is 17 unique names Wrigley FRENCH1 Wills HISTORY230 Lee Olson compsci101 fall16

Next, find the number of people taking just one course compsci101 fall16

COMPSCI101 Union all sets But French1 ECON101 Li Abroms Curtson Williams Ye MATH101 Smith Lin Noell Green Wei Delong Yavatkar Black Discuss, wouldn’t it help if you had the union of all sets but the one Wrigley FRENCH1 Wills HISTORY230 Lee Olson compsci101 fall16

To solve this problem First let’s write a helper function compsci101 fall16

Part 3 – unionAllSetsButMe bit.ly/101f16-1027-4 Given example, a list of sets of strings, and the index of one of the sets, return the union of all the sets but that one example = [set(["a", "b", "c"]), set(["b", "c", "d", "g"]), set(["e", "d", "a"])] unionAllSetsButMe(example,1) is set(["a", "b", "c", "e", "d" ]) compsci101 fall16

Part 4 – peopleTakingOnlyOneCourse bit.ly/101f16-1027-5 Given a list of lists of strings of names representing people from courses Find number of people taking just one course [[‘Abroms’, ‘Curtson’, ‘Williams’, ‘Smith’], [‘Black’, ‘Wrigley’, ‘Smith’, ‘Abroms’]] 4 If this was just our data, we have 4 people taking just one course – either econ101 or history230 compsci101 fall16

COMPSCI101 People taking Only one course ECON101 Li Abroms Curtson Williams Ye MATH101 Smith Lin Noell Green Wei Delong Yavatkar Black Wrigley FRENCH1 Wills HISTORY230 Lee Olson compsci101 fall16

APT - UniqueZoo How do you solve this problem? How is it similar to the problem we just solved compsci101 fall16

Example Data for UniqueZoo ["zebra bear fox elephant","bear crocodile fox", "rhino elephant crocodile kangaroo", "elephant bear"] fox zebra bear crocodile elephant rhino kangaroo compsci101 fall16

UniqueZoo – two zoos have unique animals fox zebra bear crocodile elephant rhino kangaroo compsci101 fall16