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 Feb 26, 2015 Prof. Rodger.
CompSci 101 Introduction to Computer Science January 20, 2015 Prof. Rodger compsci 101, spring
CompSci 6 Introduction to Computer Science October 20, 2011 Prof. Rodger.
CompSci 101 Introduction to Computer Science September 23, 2014 Prof. 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.
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 Introduction to Computer Science November 18, 2014 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 3, 2015 Prof. Rodger compsci101 spring151.
CompSci 6 Introduction to Computer Science September 13, 2011 Prof. Rodger.
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 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 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 February 25, 2016 Prof. Rodger compsci101 spring20161.
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 8, 2016 Prof. Rodger.
CompSci 101 Introduction to Computer Science March 1, 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 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Python: Control Structures
CS-104 Final Exam Review Victor Norman.
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CS 326 Programming Languages, Concepts and Implementation
CMSC202 Computer Science II for Majors Lecture 08 – Overloaded Constructors Dr. Katherine Gibson Based on slides by Chris Marron at UMBC.
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
Lists Part 1 Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Week 8 - Programming II Today – more features: Loop control
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
Lists Part 1 Taken from notes by Dr. Neil Moore
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Introduction to Computer Science
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CompSci 101 Introduction to Computer Science
Presentation transcript:

CompSci 101 Introduction to Computer Science Oct 12, 2017 Prof. Rodger compsci101 fall 2017

Announcements Reading and RQ 11 due next time APT 4 out due next Thursday Today: More on Lists Solving APTs with: while True Coming – more ways to process data Exam 1 back next time compsci101 fall 2017

Problem: Find the location of first adjacent duplicate word “This is a story story about a girl with a red hood…” Return 3 as the location of the first word that has a duplicate adjacent word (start at 0) Convert to a list of words compsci101 fall 2017

Seven Steps – Step 1 work example by hand This is a story story about a girl … Step 2 – write down what you did Step 3 – generalize, special cases Step 4 – work another example compsci101 fall 2017

Seven Steps – Step 1 work example by hand This is a story story about a girl … Step 2 – write down what you did Step 3 – generalize, special cases Step 4 – work another example Position 0 Position 1 Position 2 Position 3 Return 3 compsci101 fall 2017

Bit.ly/101f17-1012-1 compsci101 fall 2017

APTs solved in a similar way with: while True Pikachu NameGroup Talk about these where is the iteration compsci101 fall 2017

APTs solved in a similar way NameGroup Pikachu compsci101 fall 2017

compsci101 fall 2017

Pikachu APT APT: Pikachu What is the iteration? What are the choices: pi ka chu pichukarunkapi Try: Good: compsci101 fall 2017

Pikachu APT APT: Pikachu NOT VALID What is the iteration? What are the choices: pi ka chu pichukarunkapi NOT VALID pi chu ka pi ka pi chu ka pi Try: Use a while True loop How do you move through the string? Sometimes by 2 and sometimes by 3. Good: pi chu ka compsci101 fall 2017

APT NameGroup compsci101 fall 2017

APT NameGroup compsci101 fall 2017 Process it left to right in a similar way. compsci101 fall 2017

7 steps – Step 1 work example calculate(names, “joe”, “bo”, 2) moe joe sue bo joe po fa bo sue compsci101 fall 2017

7 steps – Step 1 work example calculate(names, “joe”, “bo”, 2) moe joe sue bo joe po fa bo sue YES NO Found! YES YES compsci101 fall 2017

compsci101 fall 2017

Alice programming language alice.org, Alice version 2.4 See folder AliceDemos/TheFair/ for Alice Worlds compsci101 fall 2017

Nested Loop compsci101 fall 2017

Fair Ride – Octopus compsci101 fall 2017

Wac-A-Mole compsci101 fall 2017 How is wac a mole implemented? A list of moles, go through and check if what you clicked on is in the list compsci101 fall 2017

Creating a list Given a list of numbers, create a second list of every number squared. nums = [8, 3, 5, 4, 1] sqnums = [] for v in nums: sqnums.append(v*v) print sqnums [64, 9, 25, 16, 1] Talk about append. It modifies the list. Note there is not a return value. Also note that it is a function that is applied to the list – notice the dot Nameoflist.function We have functions compsci101 fall 2017

More on List operations Previous page nameOfList “dot” function (parameter) sqnums.append(v*v) See list operations on next page Mutator vs hybrid vs return Mutator changes the list (no return value) Hybrid changes list and returns value Return – returns value, no change to list compsci101 fall 2017

List operations from book compsci101 fall 2017

Problem Remove all negative numbers from list [4, -2, 5, 6, -3]  [4, 5, 6] Two ways 1) return a new list with all negative numbers removed 2) Modify a list to remove negative numbers compsci101 fall 2017

www.bit.ly/101f17-1012-2 somenums = [3, -1, 8, -5, -2, 6, 7] nonegs = removeNegatives(somenums) compsci101 fall 2017

www.bit.ly/101f17-1012-3 somenums = [3, -1, 8, -5, -2, 6, 7] removeNegatives2(somenums) compsci101 fall 2017

www.bit.ly/101f17-1012-4 somenums = [3, -1, 8, -5, -2, 6, 7] removeNegatives3(somenums) compsci101 fall 2017

APT MorseCode compsci101 fall 2017

Solving problems – APT MorseLikeCode Compare find vs index find with string – returns -1 when not found index with list – CRASHES if not there! You can’t say: pos = alist.index(“…”) Instead: if “…” in alist: pos = alist.index(“…”) How to get started? What do you do instead? If “…” in alist, then set pos Started? Consider writing a function helper If time look at other apts such as minPalindrome compsci101 fall 2017