0% found this document useful (0 votes)
6 views

Introduction To Algorithms and Scratch

The document discusses computational thinking and algorithms, defining key programming concepts like variables, inputs, processes, and outputs. It provides examples of writing algorithms as step-by-step instructions to solve problems, such as adding two numbers or making a phone call, and introduces the basics of programming in Scratch including scripts, blocks, and conditional structures.

Uploaded by

melissa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Introduction To Algorithms and Scratch

The document discusses computational thinking and algorithms, defining key programming concepts like variables, inputs, processes, and outputs. It provides examples of writing algorithms as step-by-step instructions to solve problems, such as adding two numbers or making a phone call, and introduces the basics of programming in Scratch including scripts, blocks, and conditional structures.

Uploaded by

melissa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Computational Thinking

Computational thinking allows us to take a complex problem,


understand what the problem is and develop possible solutions.

In this lesson you will learn more about


Algorithms and how to write programs to solve simple problems
Terms used in writing program codes
• Program –statements used in coding to solve a particular problem
• Program plan – sets the input, processes it and gives the output
• Input- This is the data that is to be processed in a program
• Process – Checks if the answer in a program is right
• Output- This is data that has been processed by a program
• Variable- is where you store a value in a program
• Flow chart – Used to represent a program in pictures. Written in steps
An Algorithm
• An Algorithm –is a step by step instructions used when solving a
problem.
• When you write an algorithm, the order of the instructions is very
important.
• Algorithms can also be represented in a flow chart.
Advantages of Algorithm
• It is written in simple English language.
• Easy to understand.

Rules for Writing an Algorithm


• Always begin with 'Start'.
• Statement are written in steps as Step1, Step 2, and so on.
• Always simple and understandable language.
• Each statement should be given in separate lines.
• Always finish with 'Stop'.
Example 1) An algorithm ask a user to input two numbers, add
the numbers and print total :

• Step 1 : Start
• Step 2 : Input numbers 1 , 2
• Step 3 : Add two numbers and store as SUM
• Step 4 : Print the value of SUM
• Step 5 : Stop
Example 2) Making a phone call to your friend:
Step 1 : Start
Step 2 : Pick up the receiver.
Step 3 : Listen to the dial tone.
Step 4 : Dial your friend's number.
Step 5 : Say Hello
Step 6 : Talk to your friend.
Step 7 : Say Bye Bye, after talking.
Step 8 : Put down the receiver.
Step 9 : Stop
Example 3) To save a document in Microsoft Word
• Step 1 : Start
• Step 2 : Click on File Menu.
• Step 3 : Click on Save.
• Step 4 : Choose the target folder.
• Step 5 : Type Filename.
• Step 6 : Click on Save.
• Step 7 : Stop

Example 4) Calculate the area of a room


• Step 1 : Start
• Step 2 : Read L and B as length and breadth.
• Step 3 : Multiply L and B & store as A.
• Step 4 : Print A.
• Step 5 : Stop
Programming in Scratch: Introduction
1 ) Scratch Editor
The Scratch editor has three main parts:

• Stage: Where your program runs.


• Sprite list: A list of the sprites (objects) in your program.
• Script editor / costume editor: Where you edit your programs or your
sprite’s pictures.
2) Script editor

Script editor has three main parts

1.Script area: Where you build scripts.


2.Block menu: Where you choose the category of blocks (programming
statements) to use.
3.Block palette: Where you choose the block to use
1) Variables
• A variable is where you store a value in a program
Creating a variable:
• On the block menu select Data block (Orange dot), then make
variables with different names:
Using a variable in scratch
• Choose a variable that you have created from the drop down list and
fit the block to your program
2) Operators
• Operators are used to process a value in a program
• Represented in a Green block
3) Relational operators

• Relational operators in are used to compare two values.


• For example: 3=3, 3 > 2, 10 < 20
• Some common relational operators include:
Logical tests

• A logical test is a test that has the answer as either True or False.
• They are used together with relational operators
• For example:
a) 4 > 3 ? The answer is True
b) 10 < 5 ? The answer is False
c) 50 = 10 ? The answer is False
2) Logical operators block:
• To make a logical test a relational operator is used.
• Relational operator are represented in ‘green dot’
• Let us now use the conditional if…then block with relational operator
block.
Creating a Program using conditional structures
1) If….then block
a) Found when you click on the orange dot
b) Has several blocks: Repeat, forever, repeat until…
c) Used together with relational operators
Run the program and see what happens
2) If…..else block

• If ….else block is used when we want to have two different outputs in


a program
• The if…else block starts with logical test and can give output as either
TRUE or False.
• In a complete program it should be used with a logical test.
• Sample project code that uses if….else block.
• Run and see what happens
More example on Scratch Programming
Simple Exercise for an Algorithm
• Create an algorithm that shows how you prepare your favorite
meal/snack/recipe
Writing Algorithms the solving problems in scratch
Here you will learn three things:
(a) How to break down a problem
(b) Plan for the solution of the problem
(c) Make a scratch program

Sample scratch program.


Problem: calculate the addition of two numbers input by a user

Solution
1.Create an algorithm
2.Create a program plan
3. Solve using scratch
Exercise 1
Problem: Calculate the addition of two numbers input by a user

How to solve the problem


1.Create an algorithm
2.Create a program plan
3. Solve using scratch
Step 1: Creating an algorithm
• Step 1:Start
• Step 2: Asks the user to enter first number
• Step 3: Read the number and store as Variable A
• Step 4: Asks the user to enter second number
• Step 5: Read the number and store as Variable B
• Step 6: Add two numbers and store as Variable Sum
• Step 7: Print the sum of A and B
• Step 8: Stop
3) Solving the problem using scratch

You might also like