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

Exploring Programming Stage 6 Cambridge PPT

The document provides an overview of programming concepts, focusing on algorithms, flowcharts, and the use of procedures to create shapes and patterns. It covers the characteristics of algorithms, the importance of decomposition, and the use of repetition in programming. Additionally, it includes practical examples and exercises related to drawing shapes using programming tools like Scratch.

Uploaded by

saanvi.parashar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Exploring Programming Stage 6 Cambridge PPT

The document provides an overview of programming concepts, focusing on algorithms, flowcharts, and the use of procedures to create shapes and patterns. It covers the characteristics of algorithms, the importance of decomposition, and the use of repetition in programming. Additionally, it includes practical examples and exercises related to drawing shapes using programming tools like Scratch.

Uploaded by

saanvi.parashar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 82

Exploring Programming

Aim
You will learn to:
•plan an algorithm to draw a simple repeating shape or pattern
•create a program to produce a simple repeating shape or pattern
•predict the output of a program that includes repetition
•plan an algorithm to draw a complex shape or pattern, using
decomposition
•create a procedure and use it in a program to draw a complex shape
or pattern.
•use the pen to draw lines and shapes
•change the colour and size of the pen.
Introduction to Algorithm
Objectives

● Understand Algorithm
● Defining an algorithm
● Writing Algorithms
Algorithm is...
● An effective method expressed as a finite list of
well-defined instructions in a sequential way to solve
problems.

For example: You follow set of instructions in sequence


to make a recipe.
Characteristics of an algorithm

Well-defined Inputs Well-defined Outputs

Characteristics of an
Definiteness Finiteness
algorithm

Language
Effectiveness
Independent
Finiteness: The algorithm must always terminate after a finite number of steps.
Definiteness: Each step must be precisely defined; the actions to be carried out
must be rigorously and unambiguously specified for each case.
Input: An algorithm has zero or more inputs, taken from a specified set of
objects. Most algorithms require data values to define the specific problem.
Output: An algorithm has one or more outputs, which have a specified relation
to the inputs.
Effectiveness: All operations to be performed must be sufficiently basic that
they can be done exactly and in finite length.
Write an algorithm to bake the cake in Microwave
oven. Your algorithm should include all the required
information.
Addition of two numbers - Arrange instructions in order

Instructions Order

Sum the two numbers


Start the process
Display the sum
Stop the process
Input number1 and number2
Addition of two numbers - Arrange instructions in order

Instructions Order

Sum the two numbers 3


Start the process 1
Display the sum 4
Stop the process 5
Input number1 and number2 2
Example
Leave Home

See the time

No Before Yes
Take Bus Take Subway
7am?

Reach School
1. Start from home
2. Check time
3. If time is before 7am, take subway path to reach
school
4. Else, take school bus to reach school
Flowchart...

● Graphical representation of an algorithm steps.

● Defined with symbols and arrows.

● Shows steps in sequential order.

● Used in presenting flow of algorithms, or everyday task.


Find out more...

Write other areas where flowchart can be used.


Flowchart Symbols
Symbols Functions
Terminator - Beginning/End of a program.

Process (Any processing/computational function).

Decision (Decision point between two or more paths in a


flowchart).
Data (Represent any type of Input/Output data in a
flowchart).
Connector to show a jump from one point in the process flow
to another.
Flow lines (Shows the direction of flow/ Sequence of
operation)
Flowchart for the sum of two
numbers
Write the functions of the flowchart symbols given here.
1. Pick up a pen a) How many times the actions are repeated?
2. Put it back down
3. Pick up a pen
4. Put it back down b) How many steps you write if you repeat this
5. Pick up a pen action for ten times?
6. Put it back down
7. Pick up a pen c) How you reduce the steps to repeat the action
8. Put it back down for ten times?
9. Pick up a pen
10. Put it back down
Algorithm for repeating actions
Repetition is the
process of doing
some process (or)
1. Pick up a pen action more than
2. Put it back down once.

3. Repeat steps 1-2 for 5 times


Flowchart for
repeating actions
Draw a flowchart for reduced steps.
Flowchart Algorithm

1. Colour in 10 Squares up.


2. Colour in 5 Squares to the right.
3. Repeat steps 1-2 for 4 times.
Algorithm

1. Move forward 20 steps


2. Turn right 45 degrees. Task
3. Move forward 20 steps
4. Turn right 45 degrees Reduce this algorithm using Repeat
5. Move forward 20 steps statement.
6. Turn right 45 degrees
7. Move forward 20 steps
8. Turn right 45 degrees.
9. Move forward 80 steps
Algorithm with reduced steps

1. Move forward 20 steps


2. Turn right 45 degrees.
3. Repeat steps 1-2 for 4 times.
4. Move forward 80 steps
Draw a flowchart for the previous algorithm (slide no 25)
Algorithm
1. Move 110 steps forward
2. Turn right 160 degrees
3. Move 115 steps forward
4. Turn left 160 degrees
5. Move 110 steps forward
Flowchart
This represents the amount of turn(angle) that the sprite
would make.
Algorithm
1. Move 150 steps forward
2. Turn left 60 degrees.
Try this...
Algorithm
1. Move 100 steps forward
2. Turn right 90 degrees
3. Move 100 steps forward
4. Turn left 135 degrees
5. Move 130 steps forward
Write algorithm and flowchart for this...
Scratch Tool Link
Coordinates of
Scratch Stage
1. To import Pen block click Add
Extension.

2. Choose Pen Extension


Clockwise Direction

● An angle is the degree that


you have to turn.

● An image shows common


angles if you are turning to
the right (clockwise).

● All the turn must add up to


360 degrees.
Anti-Clockwise Direction

● Angles are reversed if you


are turning to the left
(anti-clockwise).

● The complete circle is 360


degrees.

● All the turn must add up to


360 degrees.
Code - Drawing line using Sprite Output - Drawing line using Sprite
Code - Drawing line using Sprite

Now, add “erase all” block


as shown in the code and
check the output.
Code - Drawing line using Sprite

1. Now, add “wait” block as


shown in the code and check
the output.

2. Next, change wait block


second value to “5” and
check the output.
Code - Drawing line using Sprite

Now, add the last two blocks


and check the output.
Code - Drawing line using Sprite

Now, add “pen up” block as


shown here and check the
output.
Drawing Regular Polygons
Properties of Regular Polygon
● It is closed shape.
● All sides are equal in length and equal in angle.
● Formula to calculate exterior angle for each side is,
360/Number of Sides

Square - 4 Sides → 360/4 = 90 degrees each side


Triangle - 3 sides → 360/3 = 120 degrees each side
Pentagon - 5 sides → 360/5 = 72 degrees each side
When you add all the
exterior angles of
regular polygon, you
always get 3600
Code - Drawing Square without repeat

1. Check the output of this code.


2. To check program flow, add
“wait” block between “turn” and
“move” blocks.
Program to draw a square with
repeat block

Number of Sides

360/Number of Sides
Flowchart to
draw Square
Operators Block

To do some mathematical calculation such as


addition, subtraction, multiplication and division
for the values in the program.

To select random values between the values.

These comparison blocks which are used in Control


blocks to compare values.
Use operator block to
calculate degrees

Change pen color for each side.


Flowchart to
draw Pentagon
Use ask command in
sensing block to get
number of sides as input.

“answer” command returns the value


entered on the screen as input.
Use IF-ELSE command in
Control block to prompt the
user to enter number of
sides greater than 2.
What is the difference between IF and IF-ELSE?
In IF, the statements inside the if block executes if the expression is true. If the
expression is false the next statement after the if block executes.

In IF-ELSE, the if block executes if the expression is true and if the expression is
false the control is passed to the else block.
What is the difference between REPEAT and
REPEAT-UNTIL command?
Which command will be used to ask input repeatedly till
the user enters correct value?
Use REPEAT-UNTIL
command in Control block
to ask repeatedly until the
user enters correct value.
What is Variable?
Variables are used to store information to be referenced
and manipulated in a computer program.
Variable Block
It gives the value of the variable.

To set (or) assign any value of a selected variable.


Here, “my variable” is assigned to the value 5

Add (or) reduce the value of selected variable by the


given value.
Show value of the selected variable on the stage.y

Value of the selected variable not displayed on the


stage.
Use variables to store
side value and step value
entered by the user.
Nested Repeat Loop Example and Output

Nested loop is defined as a


loop within another loop.

Outer Loop. This loop


draw triangle 10 times

Inner Loop. This loop


draw a triangle shape
A Spinning Triangle

To draw spinning shape, calculate outer loop repeat


times by dividing 360 with outer turn degrees.
(OR)
Calculate outer turn degrees by dividing 360 degrees
with outer loop repeat times.
A Spinning Triangle - Output
Activity - 1

Write a program to
draw Lollipop. Use
change pen size and use
different pen color for
each octagon.
Abstraction
Creating blocks/procedures is a part of the
Abstraction. Abstraction is an important part of
programming.

Abstraction is a method to simplify a problem by


hiding internal implementation details.
Real-time Example of Abstraction

Coffee Vending Machine


Mobile Phones
You just need to put milk You interact only with
and coffee powder inside buttons and no details about
the machine. how it is programmed.
Decomposition

Decomposition is the process of breaking down


larger problems in to the smaller problems to
solve.
Scratch MyBlock
Rectangle Shape
Display of two similar shapes
Output

You might also like