CompSci 101 Introduction to Computer Science March 17, 2015 Prof. Rodger compsci 101, spring 20151.

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 13, 2015 Prof. Rodger compsci 101 spring
CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
CompSci Today’s topics Java Review Just a bunch of headings meant to trigger questions A contraction of previous notes Upcoming Midterm Exam Reading.
For. for loop The for loop in Python is more like a foreach iterative-type loop in a shell scripting language than a traditional for conditional loop.
CompSci 6 Introduction to Computer Science October 20, 2011 Prof. Rodger.
CompSci 100e Program Design and Analysis II March 29, 2011 Prof. Rodger CompSci 100e, Spring20111.
Component 4: Introduction to Information and Computer Science Unit 6: Databases and SQL Lecture 3 This material was developed by Oregon Health & Science.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. Rodger.
ORDER OF CONTENT AND INSTRUCTIONS A program in its simplest form usually contains three kinds of activity:  INPUT : The program asks the user for some.
Synthesis ENGR 1181 MATLAB 11. Topics  No new material  Covers topics that will be on the Midterm 2 Exam MATLAB 01 – Program Design MATLAB 02 – Introduction.
CompSci 4 Introduction to Programming Animation and Virtual Worlds Prof. Susan Rodger.
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 November 1, 2011 Prof. Rodger.
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.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
CompSci 6 Introduction to Computer Science November 8, 2011 Prof. Rodger.
CompSci 101 Introduction to Computer Science November 18, 2014 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151.
Dr. Tami Meredith Saint Mary's & Dalhousie Universities.
CompSci 6 Introduction to Computer Science September 13, 2011 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 31, 2015 Prof. Rodger Thanks to Elizabeth Dowd for giving this lecture Review for exam.
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.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
1 COMS 161 Introduction to Computing Title: Computing Basics Date: September 8, 2004 Lecture Number: 7.
CompSci 4 Chap 9 Sec 1 October 28, 2010 Prof. Susan Rodger.
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 6 Introduction to Computer Science Sept. 20, 2011 Prof. Rodger CompSci 6 Fall
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
CompSci 101 Introduction to Computer Science November 11, 2014 Prof. Rodger CompSci 101 Fall Review for exam.
CSC 4630 Perl 3 adapted from R. E. Beck. Problem But we worked on it first: Input: Read from a text file named in a command line argument Output: List.
CompSci 4 Chap 10 November 4, 2010 Prof. Susan Rodger.
VB.NET and Excel VB.NET allows you to write code to manipulate Excel. You can create, open, and save Excel files. You can read data from Excel. You can.
CompSci 101 Introduction to Computer Science February 25, 2016 Prof. Rodger compsci101 spring20161.
Island of Logic Assignment #4 Programming Language, Spring 2003.
For Loop GCSE Computer Science – Python. For Loop The for loop iterates over the items in a sequence, which can be a string or a list (we will discuss.
CS100 - PYTHON – EXAM 2 REVIEW -ONLY THE VITAL STUFF- PYTHON STRING METHODS, LOOPS, FILES, AND DICTIONARIES.
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 April 7, 2015 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 24, 2016 Prof. Rodger compsci 101, spring
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 April 14, 2016 Prof. Rodger compsci101 spring161.
CompSci 101 Introduction to Computer Science February 5, 2015 Prof. Rodger Lecture given by Elizabeth Dowd compsci101 spring151.
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 6 Introduction to Computer Science
Tuples and Lists.
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
Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CS150 Introduction to Computer Science 1
CompSci 101 Introduction to Computer Science
CISC101 Reminders Assignment 2 due today.
Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Presentation transcript:

CompSci 101 Introduction to Computer Science March 17, 2015 Prof. Rodger compsci 101, spring 20151

Announcements For next time, Reading and RQ14 APT 6 due today, APT 7 out Assignment 6 out soon! compsci 101, spring 20152

Alice programming language alice.org, Alice version 2.4 3

Nested Loop compsci 101, spring 20154

Fair Ride – Octopus compsci 101, spring 20155

Wac-A-Mole 6

Problem: Longest Name Given a list of names (one word only) and a letter (assume names start with capital letter, and letter is capital) names = [‘Helen’, ‘Bob’, ‘Bart’, ‘Hugh’] 1) Find the longest name that starts with that letter 2) Find the position of the longest name that starts with that letter See longestName.py, DO NOT use enumerate 7

Enumerate An iterator, generates a sequence Generates tuples of (index, item) Used with for loop to get both index and item for (index,item) in enumerate(somelist): –You get both at the same time! Redo find position of longest name with iterator compsci 101, spring 20158

Problem: Popular Name Given a list of names, determine the most popular first name and print that name with all of its last names. Input: Names are always two words, names are in a file. If multiple names are on the same line they are separated by a “:” Output: Most popular first name, followed by a “:”, followed by corresponding last names separated by a blank compsci 101, spring 20159

Example Input File with 5 lines Susan Smith:Jackie Long:Mary White Susan Brandt Jackie Johnson:Susan Rodger:Mary Rodger Eric Long:Susan Crackers:Mary Velios Jack Frost:Eric Lund Corresponding Output Susan: Smith Brandt Rodger Crackers compsci 101, spring

One way to solve Create a list of unique first names Create a list of lists of last names that are associated with each first name compsci 101, spring

Example – two lists ’Susan’’ ‘Jackie’ ‘Jack’ ‘Eric’ ‘Mary’ [ ‘Smith’,‘Brandt’,‘Rodger’,‘Crackers’]’ [ ‘Long’, ‘Johnson’]’ [ ‘White’,’Rodger’,’Velios’]’ [ ‘Long’, ‘Lund’]’ [ ‘Frost’]’ Unique First names Corresponding Last names compsci 101, spring

Now can we solve the problem? Compute those two lists that are associated with each other –List of unique first names –List of corresponding last names Compute the max list of last names Now easy to print the answer. See popular.py compsci 101, spring

Look at the code for popular.py Which datafile is read in? What format is namelist in? Write the code for uniqueFirstNames compsci 101, spring

Write the code: uniqueLastNames correspondingLastNames printFirstWithLasts compsci 101, spring

Finish maxnum = max([len(item) for item in lastNames]) print maxnum lastIndex = [index for (index, v) in enumerate(lastNames) if len(v) == maxnum] print "first name with most last names is:" compsci 101, spring

Expanding the Problem Suppose we want to read from multiple data files names1.txt, names2.txt, names3.txt See processFiles in popular.py compsci 101, spring