Intro to CS Sept 22/23, 2015.

Slides:



Advertisements
Similar presentations
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?
Advertisements

ArrayLists The lazy mans array. Whats the matter here? int[] list = new int[10]; list[0] = 5; list[2] = hey; list[3] = 15; list[4] = 23;
Roles of Variables with Examples in Scratch
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.
CS0004: Introduction to Programming Repetition – Do Loops.
Mr. Wortzman INTRO. TO COMPUTER SCIENCE. UNIT 1 – CUSTOM BLOCKS.
Lilian Blot CORE ELEMENTS COLLECTIONS & REPETITION Lecture 4 Autumn 2014 TPOP 1.
CSC 1701B Computing: Science and Creativity. Outline  Types  Variables  Operators  Control: sequence, selection, repetition  Functions (block headings.
COMPUTER SCIENCE FEBRUARY 2011 Lists in Python. Introduction to Lists Lists (aka arrays): an ordered set of elements  A compound data type, like strings.
October 4, 2005ICP: Chapter 4: For Loops, Strings, and Tuples 1 Introduction to Computer Programming Chapter 4: For Loops, Strings, and Tuples Michael.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 8 Lists and Tuples.
Loops & List Intro2CS – week 3 1. Loops -- Motivation Sometimes we want to repeat a certain set of instructions more than once. The number of repetitions.
LISTS. LEARNING OBJECTIVES Create a block that accepts a parameter Create a block that returns a value Create scripts that manipulates lists Incorporate.
LISTS and TUPLES. Topics Sequences Introduction to Lists List Slicing Finding Items in Lists with the in Operator List Methods and Useful Built-in Functions.
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.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
CMSC201 Computer Science I for Majors Lecture 08 – Lists
String and Lists Dr. José M. Reyes Álamo.
August 31 Intro to CS.
Topic: Iterative Statements – Part 1 -> for loop
Madlib-Input, Strings, and Lists in Scratch
BIT116: Scripting Loops.
Containers and Lists CIS 40 – Introduction to Programming in Python
Topics Introduction to Repetition Structures
Chapter 4 Strings & Tuples
Organization of Programming Languages
August 30 Intro to CS.
Intro to CS Monday, August 29
Diamond Hunt Mock Programming Project.
Intro to CS Monday, August 24
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Topics Introduction to Repetition Structures
CISC101 Reminders Quiz 2 this week.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Last Class We Covered Data representation Binary numbers ASCII values
Topics Introduction to File Input and Output
CISC101 Reminders Slides have changed from those posted last night…
CS190/295 Programming in Python for Life Sciences: Lecture 6
Lesson 09: Lists Topic: Introduction to Programming, Zybook Ch 8, P4E Ch 8. Slides on website.
Data Structures – 1D Lists
4. sequence data type Rocky K. C. Chang 16 September 2018
Intro to Computer Science CS1510 Dr. Sarah Diesburg
String and Lists Dr. José M. Reyes Álamo.
More Looping Structures
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Topics Sequences Introduction to Lists List Slicing
Programming Control Structures with JavaScript Part 2
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Game Over Module 4 Lesson 2.
Topics Introduction to File Input and Output
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CISC101 Reminders Assignment 2 due today.
Introduction to Computer Science
Topics Sequences Introduction to Lists List Slicing
And now for something completely different . . .
Introduction to Computer Science
Intro to Computer Science CS1510 Dr. Sarah Diesburg
More Looping Structures
Winter 2019 CISC101 5/26/2019 CISC101 Reminders
Topics Introduction to File Input and Output
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Lecture 20 – Practice Exercises 4
Python List.
Week 7 - Monday CS 121.
Introduction to Computer Science
Presentation transcript:

Intro to CS Sept 22/23, 2015

Today Review Project 1 Unit 2 Introduction Lists Project 2

Review Project 1 (Mario) Mario/Hero moves left, right, up (Motion Category) Villian continuously slides back and forth (Motion Category) Scenary Sprites move if Mario/Hero moves (broadcasting & receiving; sense of dependency) (Control Category Scenary: When Hero and Villian are touching, game over, and all scripts stop.

Shopping List

List Examples PB & J ingredients A set of numbers Letters in words Things to buy at the grocery store

What is a list? A finite , ordered, collection of  items, where the same value may occur more than once

Lists Finite – having a limit or bounds Ordered – the sequence of items matters Collection – a bundle of items

List is a Data Type A regular variable stores a single item a = 1 A list can store multiple items of data nums = [15, 3, 15, 18] The data is stored sequentially in list items, aka, list values

The items are indexed starting at 1 List index and length The items are indexed starting at 1 [Python index starts from 0] The list has a finite length of 4 Index 1 2 3 4 Value 15 7 18

groceryList = [vegetables, fruit, milk] List of String Values groceryList = [vegetables, fruit, milk] This list has a finite length of 3 List can have different item types Index 1 2 3 Value vegetables fruit milk

List Operations Initialization Indexing Length Add Insert

Making Lists in SNAP! Creating a List is like creating a Variable …kind of. Step 1. Step 2.

Initialization Python: groceryList = [vegetables, fruit, milk]

Item, Index and Length Items are numbered with an index (starting at 1) A list has a notion of length 1 min EXAMPLE: “vegetables” is an item Its index is “1” The list “groceryList” has a length =3

Indexing an Item in List Returns the item in the list with index 1: “vegetables” Can be used in other blocks such as Boolean or Say The Python way, groceryList[0] 30 secs

Length Returns the length of the list Can be used in other blocks such as Boolean or Say The Python way, len(groceryList) 30 secs

Add The add operation put the values at the end Assigns the “groceryList” variable to an empty list Adds “vegetables” to the end of the list Adds “fruit” to the end of the list Adds “milk” to the end of the list The add operation put the values at the end In Python, it’s called “append”

Insert create empty list add “fruit” to end add “milk” to end add “vegetables” to end add “fruit” to end add “milk” to end 30 secs insert “eggs” at position 1

Compare Add and Insert “Add” places “thing1” at the end of the list “Insert” places “thing2” at the designated spot, 1 30 secs

Exercise 1: Making a Shopping List Make a list with the same order as this one. Use at least one “insert” block. Save your work in SNAP! as “Shopping List”

What worked? What was difficult? Exercise 1 Recap: What worked? What was difficult?

Review: List A finite, ordered, collection of  items, where the same value may occur more than once In computer science, List is a Data Type that can store multiple items of data Items in a list can be indexed List has a length

The items are indexed starting at 1 List index and length The items are indexed starting at 1 [Python index starts from 0] The list has a finite length of 4 Index 1 2 3 4 Value 15 7 18

Initialization Python: groceryList = [vegetables, fruit, milk]

Indexing an Item in List Returns the item in the list with index 1: “vegetables” Can be used in other blocks such as Boolean or Say The Python way, groceryList[0] 30 secs

Length Returns the length of the list Can be used in other blocks such as Boolean or Say The Python way, len(groceryList) 30 secs

Compare Add and Insert “Add” places “thing1” at the end of the list “Insert” places “thing2” at the designated spot, 1 30 secs

List Operations Initialization Iterate Indexing Delete Length Add Insert Iterate Delete Clear – delete all Replace

Iteration – For each For each – iterate over items directly 30 secs For each – iterate over items directly Python: for item in groceryList:

Iteration – For loop For Loop – iterate over items using index 30 secs

Iteration - Repeat “Repeat” 30 secs

Exercise iteration: Make a global groceryList Make an iterateForEach block that takes inputList as argument and iterate over inputList to say the items Make a showGroceryList that invokes iterateForEach

Iterate: For Each

Duplicate Items 30 secs

Delete “Delete all” deletes all items in the list 30 secs “Delete all” deletes all items in the list Python del groceryList[:]

Replace 30 secs

Project #2: Mario with Lists

Mario List 1.  Learn how to access already existing lists - xList & yList - in order to make Mario jump 2. Create an empty list - performanceList. 3. Append values into the performanceList -  which will record the speeds at which Mario successfully jumps over the gremlin.

List Operations Initialization Indexing Length Add Insert

SNAP! User’s Manual http://snap.berkeley.edu/SnapManual.pdf Ch 1. Blocks, Scripts, Sprites Ch 2. Saving and Loading projects Ch 3. Building a Block Ch 4. First Class Lists Ch 5. Typed Inputs Ch 6. Procedures as Data Ch 7. Object Oriented Programming Ch 8. The Outside World Ch 9. Continuations Ch 10. User Interface Elements Index

Project 2 (Mario with Lists)

Reminders Read Chapter 2 before the start of class on Wednesday Test on Friday next week on SNAP!

Unit 2: Looking ahead Monday Wednesday Friday 14 Unit 2 start - Lists 16 Quiz on BtB Chapter 2 18 21 23 25 Test Project #2 due 6pm SCHOOL BREAK 5 Start Unit 3 - Python 7 Quiz on BtB Chap 3 9