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

Lab # 2

Uploaded by

au00152
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)
20 views

Lab # 2

Uploaded by

au00152
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/ 28

Lab # 2 (Introduction to

Scratch and Basics)


EC-120 Computer Organisation
At A Glance

• Introduction
• Logic in Daily Life
• What is a programming language?
• What is Scratch?
• Building Blocks in Scratch
• Events
• Looks
• Sensing
• Variables
• Operations
Logic in Daily Life

• We use logic in everyday life without even realising it

• We plan a route to get from destination A to B in minimum time

• We choose our outfit depending on the weather/temperature

• While using an ATM, we withdraw an amount less than our balance


Logic in Daily Life and Computer Organisation

• Google Maps handles millions of requests of route planning


everyday

• Weather/Temperature information is accessed by millions of users

• ATMs around the country performing withdrawals with no delay


Programming Languages

• A programming converts logic into code

• A programming language “tells” the computer what to do

• Instructions for a specific task are encoded in a language

• A computer understands these instructions and performs the task


Programming Languages

• Three types of programming languages:


• Machine
• Assembly
• High Level

• Assembly and High Level languages are


used more often
MIT Scratch

• Code-less coding

• A block-based,
drag-and-drop
visual programming
language

• Building blocks fit


like puzzle pieces
to perform
different tasks
What’s Possible with MIT Scratch?
Hello, World!

• Our first program is saying hello to the world in Scratch

• All you need is 2 ‘blocks’


Building Blocks in Scratch
Building Blocks in Scratch

Motion Movements of sprites like angles and position

Looks Controls the visuals of the sprite

Sound Plays audio files and effects

Events Event control

Control Conditionals and loops etc.

Sensing Sprites can interact with the surroundings


Operations Mathematical operators, comparisons
Variables Variable and Lists of usage and assignment
Variables

• A variable provides a “slot” or a “container” to hold a certain value or


some data
Variables

• A variable can hold your name or your age

• A variable can be set to a specific value and altered as


needed

• Variables can also be used to make comparisons


Variables (Examples)

• Display a value that is stored in a variable

• Input your name and let the Sprite say it back

• Take an input from the user and display the next number from it
Variables (Solutions)
Variables (Practice Questions)

• Take length of a side of a square as input from the user and display
the value after adding 5 to it.

• Imagine that you buy toffees everyday. You need to create a variable
to keep track of how many toffees you buy everyday.
Aside: Comments

• Comments are used to describe what is happening

• Comments can help understand the code quickly


Operators in Scratch

• Specific blocks which accomplish a specific mathematical/logical task.

• Scratch operators can be divided into the following categories:


• Arithmetic Operators
• Relational Operators
• Logical Operators
• Same as those used in maths in daily life:
+, -, *, / etc.
Suppose A = 10 and B= 20

Operators: Arithmetic Operators


• Relational operators check the
“relation” between two
numbers
• Suppose A = 1 and B= 0

and
and

or
or

not and
not

Operators: Logical Operators


Operations (Examples)

• Take length of a side of a square as input from the user and display
the value after adding 5 to it.

• Take 2 numbers from the user and add them together

• Take two integers as input and check whether the first number is
greater than the second or the second number is greater than the
first.
Operations (Solutions)
Operations (Practice Questions)

• Take two integers from the user and figure out whether the first
integer is a multiple of second.

• Take in the radius of a circle as an integer and display the circle’s


diameter, circumference and area. Use the constant value 3.14159 for
π.

• Design a simple AND gate.


Creating
A New
Project
Saving
A New
Project
Loading
A Saved
Project
Lab Material

• Lab Manuals
• Assignments
• Mark sheet lab

You might also like