1 of 17

Input, Output

And Math

2 of 17

Real Life: Input/Output

  • When we hear something (input) brain process it and then we can identify what it is. We then respond back. (output)
  • Washing Machine: we select the mode (input), it cleans (process) and our clothes are washed (output)
  • We we select the mode (input) , it speeds up (process) and finally it gives us cool air (output)
  • We type a number (input) and then add operation signs (process) and we get the result (output)

3 of 17

Real Life: Variables

  • Your taking a few courses in high school, however until you enrolled there were variables on which course you would enroll in.

  • You want to bake a cake. You assign ingredient totals that you need to a value. The ingredient is the variable. The amount needed is the assigned value to each variable.

Course Credit You Need (Variable)

Course you enrolled in (assigned value to variable)

Language

English

Science

Biology

Math

Data Management

4 of 17

Real Life: Debugging

  • How do you know:
    • not to walk into walls?
    • put your hand on a hot stove?

Answer: Debugging. Everyday you asses results and correct to get a desired outcome.

5 of 17

Sidebar with commands

all color coded

Switch between code, costumes

and sounds

Area for

your code

Start and stop

your code

See what you

see

Sprites

Add Sprites

Backgrounds

6 of 17

Code

  • Drag any of the blocks from the left bar to the code area.
  • Start with an event block. You need an event to happen in order for your code to do anything.
  • When the green flag is pressed is the most popular. Your code will start as soon as you run the program.
  • Drag blocks under other existing blocks on your code area. This makes them run one after another.

7 of 17

Output in Scratch

  • there are only a few options for communicating with the user using text or numbers

8 of 17

Input in Scratch

  • many types of input (mouse, keyboard, microphone)
    • we focus on text input from keyboard
    • ask the user a question and wait for their answer

9 of 17

Variables in Scratch

  • by default, all user responses are saved in the 'answer' variable
    • treat this as temporary storage
    • create your own variables to store answers to questions

10 of 17

Creating a Variable

  • make a variable for each value you input or calculate
    • try to use good names for variables
    • short but meaningful

11 of 17

Variable Names

  • a variable name should make it fairly clear what the variable is for
    • start with a lowercase letter
    • for multiple words, use uppercase to start other words

  • avoid including words like 'a', 'the', 'of, etc…
    • if variables names are getting too long, contract the word (removing some letters, usually vowels, can work)

12 of 17

Input and Output in Scratch

Notice how he blocks are all color coded and match the same colors we looked at earlier?

Try the join command. How does it change the output?

13 of 17

Math

Basic arithmetic is available in Scratch:

  • addition
  • subtraction
  • multiplication
  • Division

Remember that Order of Operations (BEDMAS) applies to what you are doing. You can use brackets to ensure calculations are done in the order you want.

In Scratch, each of the operator "bubbles" is like a set of brackets.

14 of 17

Math

(2 - 3) + 4

See how you can add commands within bubbles? These act like brackets. For example: (3+4) / (2−5)

15 of 17

Example

Ask the user to enter 2 numbers and then display the sum.

16 of 17

Assignment Operator

  • The assignment operator is the command where we assign a value to a variable.
  • The value can be a constant or the result of a calculation.

17 of 17

Assignment To Same Variable

  • it is possible to use the same variable in the
  • assignment operation and the calculation
    • this is self-assignment
    • always do the calculation first (right side), then
  • replace the variable with the new value