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.

Slides:



Advertisements
Similar presentations
Chapter 4 Computation Bjarne Stroustrup
Advertisements

Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
 Control structures  Algorithm & flowchart  If statements  While statements.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Chapter 6 Horstmann Programs that make decisions: the IF command.
True/False. False True Subject May Go Here True / False ? Type correct answer here. Type incorrect answer here.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
An intro to programming concepts with Scratch Session 2 of 10 sessions I/O, variables, simple computing.
Computer Science 1620 Programming & Problem Solving.
The Game of Algebra or The Other Side of Arithmetic The Game of Algebra or The Other Side of Arithmetic © 2007 Herbert I. Gross by Herbert I. Gross & Richard.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
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”);
1 - buttons Click “Step Forward” to execute one line of the program. Click “Reset” to start over. “Play,” “Stop,” and “Step Back” are disabled in this.
The Scratch Calculator You are all going to be real computer programmers!!!
Ms. Deveny Second Semester  Introductions  Interview your table partner  Name  Why taking CPD  Computer experience  Favorite game?
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 24 By Herbert I. Gross and Richard A. Medeiros next.
THE BIG PICTURE. How does JavaScript interact with the browser?
Chapter 2 - Algorithms and Design
Presenting results to the USER in a professional manner 1. semicolon, disp(), fprintf() 2. Placeholders 3. Special characters 4. Format-modifiers Output.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
EXPRESSIONS AND ASSIGNMENT CITS1001. Scope of this lecture Assignment statements Expressions 2.
CSD 340 (Blum)1 Ifs. CSD 340 (Blum)2 Page that asks user for background color and changes fore color from black if user selects black as background color.
Flow of Control Part 1: Selection
Quiz Answers 1. Show the output from the following code fragment: int a = 5, b = 2, c = 3; cout
Summer Computing Workshop. Introduction  Boolean Expressions – In programming, a Boolean expression is an expression that is either true or false. In.
Writing Program Code in BASIC Write a program to prompt for and accept values into TWO variables, numx and numy. The program should square the value stored.
Scratch Programming Lesson 4 Question asking and answering.
1 Chapter 2 - Algorithms and Design print Statement input Statement and Variables Assignment Statement if Statement Flowcharts Flow of Control Looping.
Variables. Todays Lesson  In todays lesson you are going to:  Learn to use variables  Learn to ask for user input  Learn to save the users response.
Computer Science 1000 Spreadsheets IV Permission to redistribute or use these slides is strictly prohibited without permission.
Algorithms Writing instructions in the order they should execute.
Dividing Decimals # ÷ 3.5 next Taking the Fear out of Math
Decision Structures and Boolean Variables. Sequence Structures Thus far, we’ve been programming “sequence structures” Thus far, we’ve been programming.
Summer Computing Workshop. Session 3 Conditional Branching  Conditional branching is used to alter the normal flow of execution depending on the value.
Basic Conditions. Challenge: ● Ask the user his/her name ● If it’s “Wally,” jeer him ● Pause video and try on your own.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
How do you do the following? Find the number of scores within 3 points of the average of 10 scores? What kind of a tool do you need? Today’s notes: Include.
2011-T1 Lecture 10 School of Engineering and Computer Science, Victoria University of Wellington  Rashina Hoda and Peter Andreae COMP 102 Rashina Hoda.
31/01/ Selection If selection construct.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
CS 141 Computer Programming 1 Branching Statements.
1 CS161 Introduction to Computer Science Topic #6.
Controlling Program Flow with Decision Structures.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Decisions: Conditional Statements (informally called If Statements) IST 256 Application Programming for Information Systems.
Inequalities and their Graphs Objective: To write and graph simple inequalities with one variable.
Learning Javascript From Mr Saem
Introduction to programming in java Lecture 21 Arrays – Part 1.
Computer Science 1000 LOGO II. Boolean Expressions like Excel and Scratch, LOGO supports three Boolean operators less than (
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
Unit 2 Technology Systems
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Based on slides by Shawn.
Selection (also known as Branching) Jumail Bin Taliba by
Debugging and Random Numbers
IF statements.
Microsoft Visual Basic 2005 BASICS
Conditions and Ifs BIS1523 – Lecture 8.
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
Selection Statements.
Inputs and Variables Programming Guides.
Lecture 6: Conditionals AP Computer Science Principles
Programming Concepts and Database
CS2011 Introduction to Programming I Selections (I)
boolean Expressions Relational, Equality, and Logical Operators
Presentation transcript:

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 in other words, we will have to read two values from the user how do we do this?

Multiple Inputs our process seems correct, as the system is asking the correct questions, but our output is wrong. why? the answer block can only hold one value when we ask the first question, it reads the length, and stores it in answer when we read the width, it clobbers the value that was read for length hence, it is incorrectly computing area as width x width to see this, we can watch what value is stored in answer by checking the checkbox beside its block

Multiple Inputs if answer can only hold one value at once, how can we read in two values? we need to store the first value somewhere where it won’t get overwritten to do this, we will declare a variable

Variable a variable is a named location in memory for storing a value simply stated, it is a place for our program to store a value to use a variable, we must first declare it you must give your variable a name it is helpful to use a name that you will remember, and that is meaningful

Variable to store a value in a variable, use the following block: in the right input, you can put a value, or an expression that value will be stored in the variable

Notice that the value changed.

Obtaining the value of a variable the variable’s block can be used as the input to another block modify our previous example so that the sprite says what is stored by the variable.

Back to our example … recall that in our previous example, we could not store two inputs, as the second input clobbered the first to mitigate this, let’s store our first input in a variable called length let’s store the second input in a variable called width

Variables notice that the answer block and a variable block behave very similarly in fact, answer is just a predefined variable, with the exception that you cannot delete it

Boolean Expressions like Excel, Scratch supports Boolean operators two values true false three operators less than equal greater than

Write a Scratch program that asks the user for their age, and prints true if that user is old enough to vote in Canada, and false otherwise

Boolean Operators like Excel operators, we can use the Boolean operators to compare strings note that they are case-insensitive

Example: Write a program that asks for the user’s name, and prints true if the user has the same name as you, and false otherwise.

Events and Booleans you may have noticed that both the Boolean operators and the event operators have the same hexagon shape in fact, the two are very similar the event operators can be considered to be true/false statements true when the event occurs false otherwise for example, consider the touching event this event is true when Sprite 1 is touching Sprite 2, and false otherwise

Events and Booleans because of their similarity, we can use events in a similar way to Booleans recall how we could print true and false from our sprites using Boolean expressions write a program for Sprite 1 that prints true if it is touching Sprite 2, and false otherwise

Events and Booleans in some cases, we can use Booleans where we previously used events example: the y position block holds the vertical position of the sprite higher the sprite, greater than y we can see the value in this block by checking the box beside it

Events and Booleans write a program where the sprite prints “Put me down” whenever it is lifted above 50 units