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.

    csp-6-2-1: What do you think print(int(abs(-16.789))), prints?
  • -16
  • The function abs will change the negative.
  • -16.789
  • The original number will change.
  • 16.789
  • The function int will remove the decimal part.
  • 16
  • The function abs will make it positive, and the function int will cut it down to 16.


Discuss topics in this section with classmates.

Show Comments
Next Section - Naming Sets of Steps