LISTS. LEARNING OBJECTIVES Create a block that accepts a parameter Create a block that returns a value Create scripts that manipulates lists Incorporate.

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

SCRATCH Lesson Two – Interactive Concepts Using Sensing, Operators, and Variables.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
JAVA Coursework (the same for 2A and 2B). Fundamental Information The coursework is 30 marks in your O’Level = 15% of the exam Must be word processed.
Harry Potter Scratch Game
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Software Development Software Life Cycle UML Diagrams.
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
1 An introduction to programming concepts with Scratch.
CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
Computer Science 1620 Programming & Problem Solving.
ITEC Winter An intro to programming concepts with Scratch Quick intro for college citizens. George Stockman MSU CSE.
CIS101 Introduction to Computing Week 12 Spring 2004.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
The Program Design Phases
Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech June 2011.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
© 2011 Delmar, Cengage Learning Chapter 8 Building Complex Animations.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
CSC 1701B Computing: Science and Creativity. Outline  Types  Variables  Operators  Control: sequence, selection, repetition  Functions (block headings.
The Scratch Calculator You are all going to be real computer programmers!!!
LISTS. RECAP Major Topics Variables Functions Sensing Messaging OOP.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
Advanced Excel for Finance Professionals A self study material from South Asian Management Technologies Foundation.
Ms. Deveny Second Semester  Introductions  Interview your table partner  Name  Why taking CPD  Computer experience  Favorite game?
Chapter 5: Control Structures II (Repetition)
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Section 3 Calculations National 4/5 Scratch Course.
Iteration. Adding CDs to Vic Stack In many of the programs you write, you would like to have a CD on the stack before the program runs. To do this, you.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
 Make sure you are subscribed to announcements on Moodle.  Activity 4 will be due 48hrs after your lab ends.
Input, Output, and Processing
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
Database Systems Microsoft Access Practical #3 Queries Nos 215.
Developing an Algorithm
Summer Computing Workshop. Introduction  Boolean Expressions – In programming, a Boolean expression is an expression that is either true or false. In.
2015 CSE/EGR Summer Camps 1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed.
30/10/ Iteration Loops Do While (condition is true) … Loop.
Data Structures and Algorithms Lecture 1 Instructor: Quratulain Date: 1 st Sep, 2009.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
Developing an Algorithm. Simple Program Design, Fourth Edition Chapter 3 2 Objectives In this chapter you will be able to: Introduce methods of analyzing.
Algorithms Writing instructions in the order they should execute.
CONTROL FLOW The order in which blocks are executed is called the “control flow” of the script So far all our scripts have just executed blocks in the.
1 Chapter 4: Creating Simple Queries 4.1 Introduction to the Query Task 4.2 Selecting Columns and Filtering Rows 4.3 Creating New Columns with an Expression.
CS 106 Introduction to Computer Science I 03 / 02 / 2007 Instructor: Michael Eckmann.
Iteration. Iteration: Review  If you wanted to display all the numbers from 1 to 1000, you wouldn’t want to do this, would you? Start display 1 display.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Introduction to TouchDevelop Lesson 3 – Comments & Lists Created by S. Johnson
Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech.
CONDITIONALS CITS1001. Scope of this lecture if statements switch statements Source ppts: Objects First with Java - A Practical Introduction using BlueJ,
Introducing Scratch Learning resources for the implementation of the scenario
LINKED LISTS.
LISTS. LEARNING OBJECTIVES Explain the difference between the three types of blocks. Explain how a list differs from a normal variable.
Games Programming in Scratch
Madlib-Input, Strings, and Lists in Scratch
Introduction to Algorithms
Spanish Mad libs with Scratch
ECS 9/7/17.
Intro to CS Monday, August 29
Intro to CS Monday, August 24
Getting Started with Scratch
Presentation transcript:

LISTS

LEARNING OBJECTIVES Create a block that accepts a parameter Create a block that returns a value Create scripts that manipulates lists Incorporate input from the user

RECAP Major Topics Variables Functions Sensing Messaging Object Oriented Programming (OOP)

STORING DATA We learned one way of storing data. Can you recall?

STORING DATA Variables are a simple way of storing data. Data has a Type associated with it. Ex: Integer, Real, Boolean, String/Char etc. Data in real world is more complex. Think about the days of the week Actors in a play Temperatures at which elements switch between states Pricing for seats in a stadium Depending on the type of data there are different ways of storing data efficiently.

DATA STRUCTURES A data structure is a way of storing and organizing data in a computer so that it can be used efficiently. So depending on the type of data that we are working with, a suitable data structure is used. Examples of data structures - Tables, Sets, Graphs, Lists, Stacks etc. The Data structure we will be learning in this unit is……

LISTS … Lists!! Our new unit is all about Lists!!

LISTS Examples List of Students in Introduction to Computer Science class. List of Songs Downtown, Hello, Shake It Off, Uptown Funk, Habits, Animals, Bang Bang, Black Widow List of Books Fahrenheit 451, Catcher In the Rye, Harry Potter and the Sorcerer’s Stone

LISTS So what is a List? A list stores multiple values of the same data Type. Each element of the list is called an Item. Every item in the list can be accessed using its position in the list, also called its index. The size of the list is the total number of items in the list.

LISTS Operations on Lists Create a list. Add an item to the list. Insert an item into the list. Delete an item from the list. Count the number of items in the list. Replace an item in the list. Delete a List! Create a List of Lists!! Examples?

GOOD PROGRAMMING PRACTICES Continued… Modular/functions: According to the functionality of the program, write each major task as a function. Gives you the flexibility to change a certain task/function without affecting the rest of the program. This helps while working as a team. Team members can work on individual functions without having to worry about its inner workings. These functions can be called during integration. Improves readability. Comments: There is no such thing as too many comments. Helps understand the program better!

GOOD PROGRAMMING PRACTICES Continued… Help improve program maintenance. Write an Algorithm i.e. Steps in English to solve the problem/writing the steps, then code – don’t start coding right away!!

LISTS IN SNAP! Variables palette – the red blocks Lists use a variadic input – You can give it any number of inputs

LISTS AS INPUTS INTO OTHER BLOCKS The grey rounded rectangle with red rounded rectangles inside it is the visual representation of a list. Each red rectangle is one list item.

LISTS – EXERCISE 1 Create a simple list. Display the items of the List. Delete the items of the list created in Exercise 1. If you get done early: What value do you get if you call the list block with no inputs? (Use the left arrow to delete the original input slot.) Can you drag other reporters into list input slots to compute the list items? What happens if you drag a list block into an input slot that expects a number as input, such as the inputs to the arithmetic operators?

SETTING A VARIABLE TO BE A LIST

ITEMS OF A LIST To select an item of a list use the item block

BLOCKS THAT RETURN A VALUE

HOW TO RETURN THE VALUE

ASK THE USER FOR WORD

REVIEW Operations on Lists Create a list. Add an item to the list. Insert an item into the list. Delete an item from the list. Count the number of items in the list. Replace an item in the list. Delete a List! Create a List of Lists!! Examples? Blocks that Return Values

AGENDA Using Join and Split Exercise 2 – Using Join and Split Exercise 3 – Create a Word Bank. Exercise 4, 5 – Operations on Word Bank. Higher Ordered Functions: Map, Keep Items, Combine Lists - HOF

LISTS – QUICK REVIEW In Snap! we can create a List by using – found under the Variables palette. We need to create a variable ( usually named an Index ) to access the different items of the list at different positions. We can further use other functionality under the Variables palette. add to add an item to the end of the list. delete to delete an item at a specified position/index insert an item into the list at a specified position/index length of takes a list as an input and gives the length or size of the list.

JOIN AND SPLIT Use Join to combine two or more words together to make a longer sentence Use split to split up a sentence into a list

EXERCISE 2 Create a block that asks the user for a word and returns it. Create 3 lists and a block that returns a random sentence based upon the 3 lists Nouns Verbs Adjectives

HIGHER ORDER FUNCTIONS Import Tools Return a list of modified list items using an expression. Select items from a list given an expression. Combine all list items into one.

EXERCISES 1.Create a list of the Beatles Use map and the list to get a list of just the first names of the Beatles 2.Write an expression that will select all the words of at least five letters from a list. For example, if the words in the list are being, for, the, benefit, of, mister, and kite, then your block should choose the words being, benefit, and mister. 3.Use the Combine with block to create a block that computes the average of a list of numbers

LISTS - EXERCISE 3 CREATE A WORD BANK/DICTIONARY Write a function called CreateWordBank Function CreateWordBank should do the following: Create a List of random ( but common ) words. The List should have a reasonable number of words. Say for Example about 20 words. Function CreateWordBank should return the total number of words in the bank. You’ll use this function CreateWordBank in the Hangman Project.

CREATE WORD BANK

LISTS – EXERCISE 4 SIMPLE OPERATIONS ON LISTS Using the WordBank List in previous exercise: Add new words to the list. - The idea is the word bank/ dictionary can learn/ grow dynamically. - You could take the new words from the user as an input. Remove some items from the list. find out the length/size of the WordBank list and store this value in a variable.

PROJECT HANGMAN - SPECIFICATIONS Write a program to play the classic game - Hangman. The game is played between the computer program and a single user. The program should come up with a secret word and the user tries to guess this word within the lives (or chances) provided. Create sprites for various stages of Hangman. Draw the Hangman sprites according to the progress in the game.

PROJECT HANGMAN – SPECIFICATIONS CONTD. The program must use lists demonstrating some common operations on lists that we learn in this unit. The program should organize important tasks into separate functions. Last but not least - comments should be added to help understand the program better!! For this project you work in pairs.

PROJECT HANGMAN USING LISTS DETAILED INSTRUCTIONS Hangman Program should do the following: Using Lists create a word bank to store the secret words with different lengths. The Program decides on: the number of words. max length for the words in the word bank. Prompt the user for the length of the secret word. Pick a word of this length from the Word bank as a secret word to begin the game. Decide on the number of lives for Hangman – Number of lives left to be displayed for the user. Work in pairs.

SUMMARY How do you create a block that accepts a parameter? How do you create a block that returns a value? How do you incorporate input from the user?

LISTS – EXERCISE 5 SIMPLE OPERATIONS ON LISTS. Using the WordBank List in previous exercise: Write a function that takes an index as an input and returns the Word at that index from the list. Ask the user to input an Index and display the word List item at the number.

CREATE A BLOCK WITH A PARAMETER

USING SOME OF THE BUILT-IN LIST FUNCTIONALITY item list and length of

PROJECT HANGMAN USING LISTS DETAILED INSTRUCTIONS – CONTD. Create a variable called GuessedWord of same length as secret word and sets it to all blanks ‘_’ Prompt the user to guess the next letter. Check if the letter is in the secret word. If letter present in secret word, then replace the ‘_’ in GuessedWord to the letter and repeat for all occurrences of letter in the word. If not, reduce the number of lives by 1 and draw the next part of Hangman.

ASSIGNMENT - HANGMAN PROJECT 1.Using lists create a WordBank/WordStore of secret words. You could create a single list of all words you want to store or separate lists for different word lengths. You choose the words, total number of words, length of words. Ex: function CreateSecretWordBank 2.Write a function that given a length, picks a word of this length from the WordBank. Ex: function PickSecretWord 3.Write a function that takes a letter and a word and gives a word with all occurrences of the letter in the word and a “_” in places where the letter is not present. It also returns a Boolean(T or F) to signal the presence of the letter. function IsLetterPresentInWord

ASSIGNMENT - HANGMAN PROJECT 4.Write a function that works with the words with the guessed letter ( from step 3) that combines the new guessed word with the previous guessed word, so that a letter in either word is copied to the combined word at that index/location. CombineGuesses 5.Create sprites for various stages of Hangman and draw the Hangman sprites according to the progress in the game. You could also use costumes from the letters section. The program decides on the number of lives for the user.

LISTS/HANGMAN – EXERCISE 6 CREATE HANGMAN SPRITES FOR VARIOUS STAGES OF THE GAME. As part of this exercise start creating the sprites for the Hangman game.

LISTS - EXERCISES The idea is to write simple exercises in BYOB as functions that are useful for the Hangman project. You can use the functions you write here for the actual Hangman project.