Functions in Python

In this post we will:

¡Recycle!

2fazaqyizlltuiie0

Gif from: http://giphy.com/gifs/helpsgood-2FazaqYizLltuIIE0

But not as the usual way. We will use the programm we made in this post: Fun with numbers. We will do the same, but now with functions. First look how it runs:

Captura de pantalla 2017-03-09 a la(s) 10.53.42

It’s the same you already saw before. But now look at the code:

Captura de pantalla 2017-03-09 a la(s) 10.51.10

Let’s explain how it works.

(This video may help you to understand better Python functions: Python Tutorial for Beginners).

The first part as you see, is just declare functions. Thats why you write def and after the name and the variables in brackets. We need it give us the operation, that why we write return and the operation to perform, that we already describe in the post Fun with numbers. The inputs will be the same way, and the thing that changes is the math operations. We are using functions, so we don’t need to perfom it like the traditional way. We just call the function and finally we print it 😉

Leave a comment