Quiz # 4

--Originally published at Python learning

For this quiz I had to make a program that would print the smallest value and the sum of the square of three numbers given by the user (x,y, and z).

I decided to use conditionals to get the smallest value, like this:

if      x <= y <= z     or     x <= z <=y:
return x
elif   y <= x <=z    or    y <=z <=x:
return y
else:
return z

At first I didn’t put the equals in the equation, so there was trouble when two inputs were the same. However, I then added them to my code and everything was fine! When I was done this is how it looked:

quiz4

And this is how it runned:

quiz4-run


Quiz Week 4

--Originally published at Elu&#039;s Blog

This were my instructions:

For this quiz I want you to (in class) create a program with two functions:

  • def minimum_three(x, y, z):  # returns the value that is smallest of x, y and z
  • def sum_squares(x, y, z): # returns the value of the sum of squares of x, y, z

You implement these function in your own program in a file quiz4.py

You should make a main routine that asks the user for three numbers and then calls your functions to which should *RETURN* the value and you print in the main part of your program.

Captura de pantalla 2017-02-02 a la(s) 11.13.13.png

And this is how it runs:

Captura de pantalla 2017-02-02 a la(s) 11.14.43.png


Minimum and Squares

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

captura-de-pantalla-2017-02-02-a-las-10-59-14

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:

captura-de-pantalla-2017-02-02-a-las-11-09-15

?

 


Quiz 4

--Originally published at Tomas Enciso

This quiz was about creating two functions, one was to get 3 numbers and to return the smallest one. The other function has to sum up three squared numbers. The hard part was defining the function so it would do what I wanted it to do. My mistake was having the IF statements bigger or smaller than and not using equals. This of course I realized after Ken broke my program.

For me the sum of the squares was more straight forward. I just made the function have three variables and then summed them up. After that the function just returned the result which was “d”

Here’s the code:

Screen Shot 2017-02-02 at 11.02.29 AM.png

and here’s when the program actually worked:

screen-shot-2017-02-02-at-11-05-29-am


Quiz 4

--Originally published at Site Title

captura-de-pantalla-81

Como se puede observar, en este programa empezamos por definir nuestras funciones. Cómo son tres términos, utilizamos las variables x, y, y z. Una función señalará el valor mínimo de los tres términos que se ingresen y el segundo será sólo una suma de estos.

Para crear la función escribimos “def”, el término de la función y en el siguiente renglón escribimos lo que retornará, es decir la operación o término que devolverá.

Escribimos el programa principal (el cual señalamos con el #main program below”) y pedimos los tres números. Luego imprimimos los comandos de la función y listo.

Ejecutamos el Programa.

captura-de-pantalla-82

Para realizar este Quiz me basé basicamente en conocimientos adquiridos en clase.

 


Quiz W4 -Minimum and squares

--Originally published at Stuff about Python

And second quiz today, for week 4 this time. Same idea, using functions to compute the minimum and the sum of squares of three numbers.

Here were the instructions:

For this quiz I want you to (in class) create a program with two functions:

  • def minimum_three(x, y, z):  # returns the value that is smallest of x, y and z
  • def sum_squares(x, y, z): # returns the value of the sum of squares of x, y, z

This the solution I’ve come up with :

quiz4

It uses the built-in function min() that returns the smallest number from a bunch of numbers, and uses the same idea than on quiz w3 to check for the user input to make sure it can be converted to an integer.