Naming Procedures and Functions

We’ve already seen how we can use names to represent numbers (both integers like 3 and -325 and decimal numbers like 2.4 and -322.9392), strings (like "Hi There"), turtles, and images. When we do calculations using the names, the computer will look up the value for each name, and then use the value in the calculation. We can also name a sequence of statements and then ask the computer to run that sequence whenever we use that name. This is similar to asking someone to do a dance that they know, like the Macarena or Salsa. Once you know the dance you can do the steps.

a women dancing Salsa

Figure 1: A Salsa dancer

In programming there are two different terms used for a named sequence of statements: procedure and function. A procedure accomplishes some task or makes something happen, but doesn’t return anything. A function returns a result. Many procedures and functions are built into Python. The function abs returns the absolute value of its input. The function int takes a decimal number as input and returns just the integer part.

You have attempted of activities on this page