Scratch Programming II Basic 6 Basic Technology Lesson Note

Download Lesson Note
Lesson Notes

Topic: Scratch Programming II

Learning Objectives

By the end of the lesson, pupils should be able to:

  1. Apply Scratch programming to execute basic mathematical operations

Content

Mathematical Operations in Scratch

Scratch can perform calculations using operator blocks found in the Operators (green) category.

Basic Math Operators:

  1. ADDITION (+)
  • Block: [( ) + ( )]
  • Adds two numbers together
  • Example: 5 + 3 = 8
  1. SUBTRACTION (-)
  • Block: [( ) – ( )]
  • Subtracts second number from first
  • Example: 10 – 4 = 6
  1. MULTIPLICATION (×)
  • Block: [( ) * ( )]
  • Multiplies two numbers
  • Symbol: * (asterisk)
  • Example: 6 * 7 = 42
  1. DIVISION (÷)
  • Block: [( ) / ( )]
  • Divides first number by second
  • Symbol: / (forward slash)
  • Example: 20 / 4 = 5

Creating a Simple Calculator

PROJECT 1: ADDITION CALCULATOR

when flag clicked

ask [What is the first number?] and wait

set [number1 v] to (answer)

ask [What is the second number?] and wait

set [number2 v] to (answer)

set [result v] to ((number1) + (number2))

say (join [The sum is: ] (result)) for (3) seconds

 

Explanation:

  1. When program starts
  2. Ask user for first number
  3. Store in variable “number1”
  4. Ask for second number
  5. Store in variable “number2”
  6. Calculate sum and store in “result”
  7. Display answer

Creating Variables:

  1. Go to Variables category
  2. Click “Make a Variable”
  3. Name it (number1, number2, result)
  4. Click OK

PROJECT 2: SUBTRACTION CALCULATOR

when flag clicked

ask [Enter first number:] and wait

set [num1 v] to (answer)

ask [Enter second number:] and wait

set [num2 v] to (answer)

set [difference v] to ((num1) – (num2))

say (join [The difference is: ] (difference)) for (3) seconds

 

PROJECT 3: MULTIPLICATION CALCULATOR

when flag clicked

ask [Enter first number:] and wait

set [num1 v] to (answer)

ask [Enter second number:] and wait

set [num2 v] to (answer)

set [product v] to ((num1) * (num2))

say (join [The product is: ] (product)) for (3) seconds

 

PROJECT 4: DIVISION CALCULATOR

when flag clicked

ask [Enter dividend (number to divide):] and wait

set [dividend v] to (answer)

ask [Enter divisor (divide by):] and wait

set [divisor v] to (answer)

if <(divisor) = (0)> then

  say [Cannot divide by zero!] for (2) seconds

else

  set [quotient v] to ((dividend) / (divisor))

  say (join [The quotient is: ] (quotient)) for (3) seconds

end

 

Note: This includes error checking for division by zero.

PROJECT 5: COMPLETE CALCULATOR (All Operations)

when flag clicked

ask [Enter first number:] and wait

set [num1 v] to (answer)

ask [Enter second number:] and wait

set [num2 v] to (answer)

ask [Choose operation: +, -, *, /] and wait

set [operation v] to (answer)

 

if <(operation) = [+]> then

  set [result v] to ((num1) + (num2))

  say (join (join (join (join (num1) [ + ]) (num2)) [ = ]) (result))

end

 

if <(operation) = [-]> then

  set [result v] to ((num1) – (num2))

  say (join (join (join (join (num1) [ – ]) (num2)) [ = ]) (result))

end

 

if <(operation) = [*]> then

  set [result v] to ((num1) * (num2))

  say (join (join (join (join (num1) [ × ]) (num2)) [ = ]) (result))

end

 

if <(operation) = [/]> then

  if <(num2) = (0)> then

    say [Cannot divide by zero!] for (2) seconds

  else

    set [result v] to ((num1) / (num2))

    say (join (join (join (join (num1) [ ÷ ]) (num2)) [ = ]) (result))

  end

end

 

Additional Math Operations:

  1. FINDING REMAINDER (Mod)
  • Block: [( ) mod ( )]
  • Gives remainder after division
  • Example: 17 mod 5 = 2 (17 ÷ 5 = 3 remainder 2)

Program:

when flag clicked

ask [Enter number:] and wait

set [number v] to (answer)

ask [Divide by:] and wait

set [divisor v] to (answer)

set [remainder v] to ((number) mod (divisor))

say (join [Remainder is: ] (remainder))

 

  1. ROUNDING NUMBERS
  • Block: [round ( )]
  • Rounds to nearest whole number
  • Example: round(7.6) = 8, round(7.4) = 7

Program:

when flag clicked

ask [Enter decimal number:] and wait

set [decimal v] to (answer)

set [rounded v] to (round (decimal))

say (join (join (decimal) [ rounded is: ]) (rounded))

 

  1. RANDOM NUMBERS
  • Block: [pick random ( ) to ( )]
  • Generates random number in range

Program – Number Guessing Game:

when flag clicked

set [secret v] to (pick random (1) to (100))

repeat until <(guess) = (secret)>

  ask [Guess a number (1-100):] and wait

  set [guess v] to (answer)

  if <(guess) > (secret)> then

    say [Too high! Try again.] for (2) seconds

  end

  if <(guess) < (secret)> then

    say [Too low! Try again.] for (2) seconds

  end

end

say [Correct! You got it!] for (3) seconds

 

Math Practice Programs:

PROJECT 6: MULTIPLICATION QUIZ

when flag clicked

set [score v] to (0)

repeat (5)

  set [num1 v] to (pick random (1) to (10))

  set [num2 v] to (pick random (1) to (10))

  set [correct_answer v] to ((num1) * (num2))

  ask (join (join (join [What is ] (num1)) [ × ]) (num2)) and wait

  if <(answer) = (correct_answer)> then

    say [Correct!] for (1) seconds

    change [score v] by (1)

  else

    say (join [Wrong! The answer is ] (correct_answer)) for (2) seconds

  end

end

say (join [You scored: ] (join (score) [ out of 5])) for (5) seconds

 

PROJECT 7: AREA CALCULATOR

Rectangle Area:

when [r] key pressed

ask [Enter length:] and wait

set [length v] to (answer)

ask [Enter width:] and wait

set [width v] to (answer)

set [area v] to ((length) * (width))

say (join [Area of rectangle: ] (area)) for (3) seconds

 

Triangle Area:

when [t] key pressed

ask [Enter base:] and wait

set [base v] to (answer)

ask [Enter height:] and wait

set [height v] to (answer)

set [area v] to (((base) * (height)) / (2))

say (join [Area of triangle: ] (area)) for (3) seconds

 

Circle Area:

when [c] key pressed

ask [Enter radius:] and wait

set [radius v] to (answer)

set [pi v] to (3.14159)

set [area v] to ((pi) * ((radius) * (radius)))

say (join [Area of circle: ] (area)) for (3) seconds

 

PROJECT 8: TEMPERATURE CONVERTER

Celsius to Fahrenheit:

when flag clicked

ask [Enter temperature in Celsius:] and wait

set [celsius v] to (answer)

set [fahrenheit v] to ((((celsius) * (9)) / (5)) + (32))

say (join (join (celsius) [°C = ]) (join (fahrenheit) [°F])) for (3) seconds

 

PROJECT 9: PERCENTAGE CALCULATOR

when flag clicked

ask [Enter the number:] and wait

set [number v] to (answer)

ask [Enter the percentage (without % sign):] and wait

set [percent v] to (answer)

set [result v] to (((number) * (percent)) / (100))

say (join (join (percent) [% of ]) (join (number) (join [ is ] (result))))

 

PROJECT 10: SIMPLE INTEREST CALCULATOR

Formula: I = (P × R × T) / 100

when flag clicked

ask [Enter principal amount:] and wait

set [principal v] to (answer)

ask [Enter rate of interest (%):] and wait

set [rate v] to (answer)

ask [Enter time (years):] and wait

set [time v] to (answer)

set [interest v] to ((((principal) * (rate)) * (time)) / (100))

set [total v] to ((principal) + (interest))

say (join [Interest: ] (interest)) for (3) seconds

say (join [Total Amount: ] (total)) for (3) seconds

 

Comparison and Logic Operators:

  1. Greater Than (>)
  • Block: [( ) > ( )]
  • Example: 5 > 3 is true
  1. Less Than (<)
  • Block: [( ) < ( )]
  • Example: 2 < 7 is true
  1. Equal To (=)
  • Block: [( ) = ( )]
  • Example: 4 = 4 is true

Using Comparisons:

when flag clicked

ask [Enter your age:] and wait

set [age v] to (answer)

if <(age) < (13)> then

  say [You are a child] for (2) seconds

else

  if <(age) < (20)> then

    say [You are a teenager] for (2) seconds

  else

    say [You are an adult] for (2) seconds

  end

end

 

Tips for Math in Scratch:

  1. Use Variables to store numbers and results
  2. Test with Simple Numbers first
  3. Check for Errors like division by zero
  4. Use Parentheses to control calculation order
  5. Round Results when needed for cleaner display
  6. Add Instructions so users know what to do
  7. Validate Input to prevent errors

Order of Operations: Scratch follows PEMDAS/BODMAS:

  • Parentheses/Brackets first
  • Multiplication and Division (left to right)
  • Addition and Subtraction (left to right)

Example:

  • (5 + 3) × 2 = 16 (parentheses first)
  • 5 + 3 × 2 = 11 (multiplication first)

Lesson Notes for Other Classes