# 1.9 Scr0390: custom blocks in scratch 2.0  (Page 2/5)

 Page 2 / 5

If you did it all correctly, your program should calculate the square root. (For reasons that will become apparent later, I will refer to the code that you inserted as in-line code.)

## Oops, need to do it all over again

Suppose that further on in your program you discover that you need to calculate the square root of another number. And later, you discover that youneed to calculate the square root of still another number. Obviously, with a few changes, you could copy your original code and insert it as in-line code at each location in your program where you need to calculate the square root ofa number.

## Is there a better way?

However, after doing this a few times, you might start asking if there is a better way. The answer is "yes, there is a better way."

## A programming module provides a better way

The better way is to create a separate program module that has the ability to calculate the square root and to make that module available for use as a helperto your main program each time your main program needs to calculate a square root. In some programming languages, this separate program module is oftencalled a function or a method. In scratch 2.0, it doesn't have a specific name. I will refer to it as a custom block . You create a custom block in Scratch 2.0 by selecting the More Blocks toolbox shown in Image A .

## Library functions

Most modern programming languages provide a large number of pre-written functions that are already available for your use.

In addition to the library functions that are already available, if you need a function to perform some operation and there is no library function alreadyavailable to perform that operation, you can write your own function.

A similar library for mathematical functions exists in Scratch 2.0. The library is accessed using the bottom block in the Operators toolbox with the selection sqrt shown in Image B .

Image C shows the different mathematical function selections that are available in the pull down list of the block. (Note that the fourth one from the top is the sqrt function.)

## Make the function general

Normally, in the case of designing and writing a function such as one that can calculate the square root of a number, it is desirable to write it in such away that it can calculate the square root of any number (as opposed to only one specific number) . This is accomplished through the use of something called parameters.

## Pass me the number please

The process of causing a function to be executed is commonly referred to as calling the function.

When your program calls the square-root function, it will need to tell the function the value of the number for which the square root is needed. Ingeneral, many functions will require that you provide certain kinds of information when you call them. The code in the function needs this informationto be able to accomplish its purpose.

how can chip be made from sand
are nano particles real
yeah
Joseph
Hello, if I study Physics teacher in bachelor, can I study Nanotechnology in master?
no can't
Lohitha
where we get a research paper on Nano chemistry....?
nanopartical of organic/inorganic / physical chemistry , pdf / thesis / review
Ali
what are the products of Nano chemistry?
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
da
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Bhagvanji
hey
Giriraj
Preparation and Applications of Nanomaterial for Drug Delivery
revolt
da
Application of nanotechnology in medicine
has a lot of application modern world
Kamaluddeen
yes
narayan
what is variations in raman spectra for nanomaterials
ya I also want to know the raman spectra
Bhagvanji
I only see partial conversation and what's the question here!
what about nanotechnology for water purification
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
Nasa has use it in the 60's, copper as water purification in the moon travel.
Alexandre
nanocopper obvius
Alexandre
what is the stm
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Got questions? Join the online conversation and get instant answers!