Page 109 - 2502_Pakistan-kifayat_C-8
P. 109
Scratch Code Python Code
num = 40
while num <= 50:
print("Hello")
num += 5
Conditional Statements
In Scratch, conditional statements are used to make decisions — the program checks whether a
condition is true or false and then decides what to do. In Python, these decisions are made using if,
elif, and else statements, which serve the same purpose but are written in text form.
The conversion of Scratch conditional blocks to Python is shown in the following table:
Scratch Code Python Code
num = 45
if num < 50:
print("Number is less than 50.")
num = 55
if num < 50:
print("Number is less than 50.")
else
print("Number is greater than or equal to
50.")
Functions
In Scratch, functions are called custom blocks. They let you create your own blocks to perform a specific
task. This helps make your program neat and organised—especially when you want to repeat the same
actions in different places.
When converting these to Python, you use the def keyword to define a function, which also helps
organise code and avoid repetition.
The conversion of Scratch functions to Python is shown in the following table:
#Texture Programming 107

