Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.

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

Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
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?
RAPTOR Syntax and Semantics By Lt Col Schorsch
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
30/04/ Selection Nested If structures & Complex Multiple Conditions.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Wizard Game: Class-Level Variables in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
TODAY’S LECTURE Review Chapter 2 Go over exercises.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
Line up By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Summer Computing Workshop. Session 4 Loops  At the heart of their functionality, loops enable blocks of code to be executed more than once  Loops represent.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Invitation to Computer Science, Java Version, Second Edition.
Chapter 2 - Algorithms and Design
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
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.
Institute for Personal Robots in Education (IPRE)‏ CSC 170 Computing: Science and Creativity.
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.
Summer Computing Workshop. Introduction  Boolean Expressions – In programming, a Boolean expression is an expression that is either true or false. In.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
Animating Objects in Groups: Using Arrays and Lists By Ruthie Tucker under the direction of Professor Susan Rodger Summer 2008.
By Melissa Dalis Professor Susan Rodger Duke University June 2011 Multiplication Table.
A Simple Quiz: Ask User Functions. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009, added Part 2 July 2011.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
1 ball, 2 ball, red ball, blue ball By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Can I get your number? By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Balancing the scales: Inequalities By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 4 – Logical Operators & Branching.
Summer Computing Workshop. Session 3 Conditional Branching  Conditional branching is used to alter the normal flow of execution depending on the value.
CS 106 Introduction to Computer Science I 09 / 26 / 2007 Instructor: Michael Eckmann.
Nonvisual Arrays by Chris Brown under Prof. Susan Rodger Duke University June 2012.
More Python!. Lists, Variables with more than one value Variables can point to more than one value at a time. The simplest way to do this is with a List.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
Ready, SET, go! By Melissa Dalis Professor Susan Rodger Duke University July 2011.
Copyright © 2000, Department of Systems and Computer Engineering, Carleton University 1 Introduction An array is a collection of identical boxes.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
CompSci 4 Chap 6 Sec 2 Sep 30, 2010 Prof. Susan Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were not a Flutterbudget.
Computer Science 1000 Algorithms III. Multiple Inputs suppose I ask you to write a program that computes the area of a rectangle area = length * width.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 4-1 Lecture Objectives To understand: –what values can be stored in a Boolean.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
By Melissa Dalis Professor Susan Rodger Duke University June 2011
A Simple Quiz for Alice 3.2:
Let's Race! Typing on the Home Row
Microsoft Visual Basic 2005 BASICS
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Arrays, For loop While loop Do while loop
Conditions and Ifs BIS1523 – Lecture 8.
A Simple Quiz for Alice 3.2:
Introduction to TouchDevelop
Introduction to Problem Solving and Control Statements
Using Lists and Functions to Create Dialogue
Presentation transcript:

Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop

Session 6

Introduction Boolean Expressions – In programming, a Boolean expression is an expression that is either true or false. These are the Boolean logic functions we will discuss: not ( ), and ( ), and or ( ). Arrays – Arrays are used to store multiple pieces of related data of the same type in order to easily and quickly find and use the data later in the program. Since Alice is type sensitive, if an array is created, it only holds a certain type of variable. For example, if we needed to store multiple numbers for later use we could use a number array where only numbers can be stored, if we needed to store multiple words for later use, we could use a string array.

Boolean Review Some basic Boolean operators we discussed in Session 3 are listed below. These return true or false and can be used in control structures such as a conditional branch or a while loop. There are three other commonly used Boolean functions that can be combined with Boolean operators, variables, or other functions to create extremely flexible expressions.

Boolean Expressions Now we will discuss these Boolean functions and provide examples of each. Boolean functions accept Boolean parameters and return a Boolean value. The AND function is used when two conditions need to be met in order to execute specified blocks. If the first condition is true and the second condition is true, then this operator returns true. If either of the conditions are false, the expression returns false. For example: Since 3 < 4 evaluates to true and 8 == 8 evaluates to true, then the AND function returns true which makes the predicate part of the if block to evaluate to true which them makes the camera say “Hello!”

Boolean Expressions In this example, 5 isn’t less than 4 so it evaluates to false. Even though one condition is true (8 == 8), using the AND operator requires both conditions to return true. The OR operator is very similar to the AND operator except it only requires one condition to be met. Even though in this example 5 == 1 evaluates to false, all the function needs in order evaluate to true is one condition to evaluate true. The full expression evaluates true because 3 is less than 4.

Boolean Expressions The NOT function is another useful tool that changes true to false and false to true, for example: In the above example, because 5 is not equal to 3, and the not block was used, the expression evaluates to true. The NOT operator in the next example will show the if block not leading into the consequent. Because the expression 5 == 5 is true, using the NOT function causes the predicate part of the If/Else structure to evaluate to false. The say block will not be executed. These Boolean functions can be used in the conditional part of a while loop control structure but are commonly found in the predicate part of an If/Else control structure.

Arrays Arrays are an essential programming tool. As stated previously, arrays can store multiple values that the programmer may need later in their program. Creating an array, in a way, is like creating multiple variables. For example, if we were to have an array of length 5. That means we have 5 separate values held within the array. Each value in the array is indexed by a number. In programming, indices begin at zero so the first element is indexed with the number 0 and the second element is indexed with the number 1. Indexing is the way we keep track of where a specific value is located in the array. The length of an array needs to be specified by the programmer before the program begins. This means that it is impossible to change the length while the program is running.

Beginning of Spelling Check Project Let’s do a spelling check example. This may seem like an advanced example please know there are many other ways to reach the same outcome. First, find an object you like that will be giving the exam. Set up the object so it informs the user of a checking test. This test will display multiple words using the object. These words will be displayed one by one followed by a question such as “If this word is correct, type correct, if it is incorrect, type incorrect, the user then will need to respond by either typing correct, or incorrect. This means we will need at least two arrays. One to hold all the words to be displayed and the other to use as a key. The key will hold the correct answers to later be compared with the user’s responses. Drag a loop to the main method and choose 10 times. Since an Array length in Alice can’t change as the program continues, we know exactly how many values the array will be holding. For this project you will need at least two arrays each having 10 elements. You may need to use multiple variables as well.

Creating an Array Creating an array is similar to creating a variable. Let’s create everything in the world object. Click “create new variable,” select string variable and check the “make a Array” box as shown below. Also, make sure you are creating an array, not a list. Lists will be covered in the next chapter along with arrays in more detail. The window should drop down and you should add a new item until this array contains a total of 10 values (up to item 9). Note: Currently the below array has a length of 3.

Continuing Project with Arrays Now we just need to name the array and fill the values. Let’s name this array “words” and fill the items with correctly and incorrectly spelled words. These words will be displayed later by using your object’s say method and a loop. Now show the complicated version of the loop we placed earlier. This is so we can use the index inside of the loop. A loop of this nature is perfect for stepping through an array. The index of the array begins at zero and the index of this loop begins at zero. This is exactly what we need to step through the array.

Continuing Project with Arrays Drag a say method and place it inside the loop and choose “Hello” for now. Now drag the array named “words” to replace “Hello,” mouse-over “ith item from array” and select 0 for now. The first box of the “ith item from array” block represents the index of the item and the second box represents the array name and whether or not it belongs to the world or a specific object. Drag the index block (located next to the word “loop” in your loop) replace the zero in the index area of the “ith item from array” block.

Closer Look Let’s take a closer look at exactly what is going on right now. The index starts at 0, so when your object’s say method is executed, it takes the item at array index 0. The index variable then increments to 1 followed by the object’s say method being called with the item at array index 1. Let’s go ahead and test the project and see what happens. The object should go through the array of words we created. Now use the join function to join something like “The word is ” in the first part and drag the “ith item from Array” block to the second part.

Second Array Create a second array, choose type String, name this array “key,” and fill the ten values with the word “incorrect” or “correct” depending on the item at that same index in the “word” array. For example, if the item at element 0 is “translate,” the associated word that would be located in this array would be “correct” since translate is spelled correctly. On the other hand if value at index 1 of the “word” array is “truste,” the associated word would be “incorrect” because trust was incorrectly spelled. Use the join function to join a sentence such as “The word is “ joined with what the object is currently saying. It should look something like the snippet below. Put a picture right here.

Continuing Project Place an If/Else control structure inside the loop below the current block. We will need at least two variables, one is a string variable named temp, the other, a number variable named count with initial value of 0. Set the temp variable above the If/Else structure but below the say block. Use an “ask user for string” block as the value of the temp variable. The snippet below is what we should have so far.

Continuing Project Now drag the temp variable to the predicate part of the if/else structure, mouse-over == and choose default string. Now we will do what we did before and set it up to look like this. Notice how the marked areas are so similar. Hint: This was done in the previous slides.

Continuing Project We will now use the count variable we previously created. If the word the user entered is equal to the correct word from the key array, then count increases by 1. Below is an example of what the If/Else control structure should look like. On your own, also make additions to the program so the object responds to the answer in some way. (talking, moving, etc.) You should also have the object say the percent correct.

Project 6 Implement a program that asks the user for a list of numbers, stores those numbers into an array, then finds the largest and smallest values and prints them to the screen.