Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to CS Sept 22/23, 2015.

Similar presentations


Presentation on theme: "Intro to CS Sept 22/23, 2015."— Presentation transcript:

1 Intro to CS Sept 22/23, 2015

2 Today Review Project 1 Unit 2 Introduction Lists Project 2

3 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.

4 Shopping List

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

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

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

8 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

9 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

10 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

11 List Operations Initialization Indexing Length Add Insert

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

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

14 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

15 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

16 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

17 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”

18 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

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

20 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”

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

22 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

23 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

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

25 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

26 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

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

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

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

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

31 Iteration - Repeat “Repeat” 30 secs

32 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

33 Iterate: For Each

34 Duplicate Items 30 secs

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

36 Replace 30 secs

37 Project #2: Mario with Lists

38 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.

39 List Operations Initialization Indexing Length Add Insert

40 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

41 Project 2 (Mario with Lists)

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

43 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


Download ppt "Intro to CS Sept 22/23, 2015."

Similar presentations


Ads by Google