# 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.

#### Questions & Answers

Is there any normative that regulates the use of silver nanoparticles?
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
why we need to study biomolecules, molecular biology in nanotechnology?
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
why?
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
what does nano mean?
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
Do somebody tell me a best nano engineering book for beginners?
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
what is fullerene does it is used to make bukky balls
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
NANO
so some one know about replacing silicon atom with phosphorous in semiconductors device?
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
for screen printed electrodes ?
SUYASH
What is lattice structure?
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
While the American heart association suggests that meditation might be used in conjunction with more traditional treatments as a way to manage hypertension
Got questions? Join the online conversation and get instant answers!