KEMBAR78
Some Useless Shatt That I Needed To Log in | PDF | Inequality (Mathematics) | Software Engineering
0% found this document useful (0 votes)
19 views6 pages

Some Useless Shatt That I Needed To Log in

Chapter 8 discusses operators and conditional blocks in Scratch, detailing mathematical, relational, logical, and string operators. It explains how conditional blocks allow sprites to make decisions based on conditions using 'if-then' and 'if-then-else' structures. The chapter also includes sample programs and exercises to reinforce understanding of these concepts.

Uploaded by

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

Some Useless Shatt That I Needed To Log in

Chapter 8 discusses operators and conditional blocks in Scratch, detailing mathematical, relational, logical, and string operators. It explains how conditional blocks allow sprites to make decisions based on conditions using 'if-then' and 'if-then-else' structures. The chapter also includes sample programs and exercises to reinforce understanding of these concepts.

Uploaded by

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

Chapter 8 More on Scratch

OPERATORS IN SCRATCH

What are Operators?

Operators are blocks in Scratch that help us do math, compare things, and check conditions.
They are green-colored blocks found in the Operators category.

1. Mathematical Operators (Math)

These blocks are used to do math calculations like adding, subtracting, multiplying, and dividing.

Operator What It Does Example


+ Adds two numbers 5+3=8
- Subtracts two numbers 9-4=5
* Multiplies two numbers 6 * 2 = 12
/ Divides two numbers 10 / 2 = 5

2. Relational Operators (Comparison)


These blocks compare values and give true or false as an answer.

Operator What It Checks Example Answer


= Checks if equal 5=5 True
> Greater than 7>3 True
< Less than 2<1 False

3. Logical Operators
Used to combine multiple conditions together.

Operator What It Does Example


and True if both conditions are true age > 10 and score > 50
or True if at least one condition is day = Sunday or day = Saturday
true
not Opposite of the condition not (rainy) means it is not raining

4. String Operators (Text Operators)


Used to work with text (words and letters) in Scratch.

Operator What It Does Example


join Joins (adds) two texts together join "Hello" and "World" → HelloWorld
letter _ of _ Gets a letter from a word letter 1 of "cat" → c
length of _ Tells the number of letters in a word length of "banana" → 6
contains _ ? Checks if one word has another word in "school" contains "cool" → True
it
CONDITIONAL BLOCKS IN SCRATCH

What are Conditional Blocks?

Conditional blocks help your sprite make decisions.


They say: "If something is true, then do this…else do something else."

These blocks are like "if" questions we ask in real life:

“If it’s raining, then take an umbrella.”


“If I finish homework, then I’ll play. Else, I’ll keep working.”

In Scratch, we use:

 if–then
 if–then–else

You find them in the Control section (orange blocks).

1. if–then Block

 This block checks one condition.


 If it is true, it runs the code inside.
 If it is false, it does nothing.

Block syntax:

if <condition> then
// do something

2. if–then–else Block

 This block checks one condition.


 If it is true, it runs the first part.
 If it is false, it runs the second part.

Block shape:

if <condition> then
// do something
else
// do something else
SAMPLE PROGRAMS
Program 1: Ask the user for their name.
If the name has more than 5 letters, say: "That's a long name!"
Solution:
ask [What is your name?] and wait
if <(length of (answer)) > 5> then
say [That's a long name!] for 2 seconds

Program 2: Ask the user their score.


If score > 50, say "You passed!", else say "Try again."
Solution:
ask [What is your score?] and wait
if <(answer) > 50> then
say [You passed!] for 2 seconds
else
say [Try again.] for 2 seconds

Program 3: Create basic calculator


Solution:
ask [Enter first number:] and wait
set [num1 v] to (answer)
ask [Enter second number:] and wait
set [num2 v] to (answer)

say (join [Add: ] ((num1) + (num2))) for 2 seconds


say (join [Subtract: ] ((num1) - (num2))) for 2 seconds
say (join [Multiply: ] ((num1) * (num2))) for 2 seconds
say (join [Divide: ] ((num1) / (num2))) for 2 seconds

Program 4: Ask for player's score.


If score ≥ 100, say "Level Unlocked!" else say "Score more to unlock."
Solution:
If score ≥ 100 then
say "Level Unlocked!"
Else
say "Score more to unlock."

Program 5: Ask for two numbers.


Say which is greater or if they are equal.

Solution:
ask [Enter first number:] and wait
set [num1] to (answer)
ask [Enter second number:] and wait
set [num2] to (answer)

if (num1) > (num2) then


say (join (num1) [ is greater]) for 2 seconds
else
if (num2) > (num1) then
say (join (num2) [ is greater]) for 2 seconds
else
say [Both are equal] for 2 seconds

INPUT-OUTPUT BOOK EXERCISE

A. Tick (✓) the correct option.

1. Which conditional block has two outcomes?


o a. If-else
o b. If-then-else
o c. If-then
o d. all of the options

Answer: b. IF then else

2. __________ stores the value in a program and its value keeps on changing.
o a. Variable
o b. Constant
o c. List
o d. Block

Answer: a. Variable

3. Which of the following is not a type of comparison operator?


o a. +
o b. <
o c. =
o d. +

Answer: +

4. Which operator does not work on strings?


o a. Mathematical
o b. Relational
o c. Boolean
o d. all of the options

Answer: A. mathematical

5. Which command allows you to create a variable in a Scratch program?


o a. Create variable
o b. Make a variable
o c. Create
o d. Add variable

b. Make a variable

B. Fill in the blanks.

1. If block is found under the category of Control block.


2. Mathematical operator helps to perform calculations on variables.
3. Local variable is created for one sprite only.
4. Join operator helps to join two strings.
5. < is an example of comparison operator.

C. State True or False.

1. You cannot compare two string values in Scratch.


o True
2. A new variable is created as local variable by default.
o True
3. If block is found under the category of Events block.
o False
4. Mathematical operators allow us to perform only basic arithmetic operations.
o True
5. Repeat block is used to run a set of instructions till a condition is satisfied.
o False (This is describing the "Repeat until" block, not "Repeat")

D. Write one line code for the following statements. (Mention block/command/operators)

1. To declare a variable ‘Name’.


make a variable [Name]
2. To accept random numbers for a variable.
set [score v] to (pick random (1) to (100))
3. To count the length of a string.
length of (answer)
4. To compare two numbers and display the greater of the two numbers.
if <(num1) > (num2)> then say (num1) else say (num2)
5. To add two numbers.
(num1) + (num2)

E. Answer the following questions.

1. Name the different types of mathematical operators.

Operator What It Does Example


+ Adds two numbers 5+3=8
- Subtracts two numbers 9-4=5
* Multiplies two numbers 6 * 2 = 12
/ Divides two numbers 10 / 2 = 5

2. Which operator block would you use to join two string values?
join operator. Example-
join "Hello" and "World" → HelloWorld

3. Which block would you use to draw a circle and square?


You can use the pen extension in Scratch. Use move and turn blocks in a loop to draw shapes.

4. Which block contains the conditional blocks?


They are found in the Control section (orange blocks).

5. Why do you need a variable in a program?


Variables are used to store values like scores, names, or numbers so that we can use them later in the
program.

6. Write about the two types of variables.


o Global variable – Can be used by all sprites.
o Local variable – Used only by a specific sprite.

7. What is the difference between if–then and if–then–else blocks?


❝if–then Block
If it is true, it runs the code inside.
If it is false, it does nothing.

Block syntax:
if <condition> then
// do something

if–then–else Block
If it is true, it runs the first part.
If it is false, it runs the second part.

Block Syntax:

if <condition> then
// do something
else
// do something else

8. Describe the significance of repeat block.


The repeat block is used to repeat actions a number of times. It helps to run the same code again and
again automatically.

You might also like