--Originally published at Programming
Today we are going to implement 2 functions.
To start, we ask the user for three numbers (x, y and z), they are the ones we will use. The first thing we do with our code is import math, then we write the functions.
What will they do?
Minimum: def minimum_three(x, y, z): returns the value that is smallest of x, y and z.
And squares: def sum_squares(x, y, z): returns the value of the sum of squares of x, y, z.
After set the function we have to say what we want it returns. In the first case we use min (here the values), and in the second we use ** to raise the numbers to the square and after that + to sum. If you try to do with sum() it doesn’t work (it happens to me), because it only accepts two values and we have 3 now.
Now, let’s work with the main code. We ask for 3 number, we save them like an int.
To do the operations we call our functions (that’s what you can see in a and b, line 10 and 11) and introduce the inputs that the user gave you. Finally, we print the values with a sentence to notice the user what are we doing. This \n is just to skip a line and present the result.
This way it runs, tried with 3, 1 and 6: