# Quiz # 3

--Originally published at Python learning

For this quiz I had to make a program that would return the square and cube root of a given number. I used two mathematical functions: math.sqrt() for the square root and math.pow(); which raises a value, in this case to 1/3 to get the cube root. I also had to first import math module.

This is how my code looked at the end:

And how it runned:

# Quiz W3 – Functions

--Originally published at Stuff about Python

Earlier this week (woops, it’s been a while), we got a quiz in class, here are the instructions:

For this quiz, create a program with two functions:

• def square_root(x):  // returns the square root of x (float)
• def cube_root(x): // returns the cube root of x (float)

The whole point of this quiz was being able to create and then call functions, so I created the functions needed to perform the actions required, as you can see in the solution below.

The square_root function uses the math module, which I imported previously, to get the square root of a number more easily.

The cubic root is then computed in another function.

The run() function is my way of making sure the user enters an input that can be converted to a number, and if not, it will raise an error and try again.

# Quiz 3

--Originally published at Tomas Enciso

For the quiz in week 3 we had to write a program using functions, these functions had to get the square root of a number and the cube root of the same or a different number, any number is valid except for negative numbers, this you can evade by having an IF statement so that if the user decides to enter a negative number, the program won’t allow it.

Down here is the code that I wrote for this quiz:

As you can see first of I had to import sqrt and pow from the math module, this is so I can use the square root and the cube root in my functions.

Heres the program running in the first one I used positive numbers and in the second image I used negative numbers so you could see the difference.

# Quiz Week 3

--Originally published at Programming

Here we are going to create a program with two functions:

• def square_root(x):  // returns the square root of x (float)
• def cube_root(x): // returns the cube root of x (float)

We should ask the user for a number and then, print the square and cube roots out.

So, here is the code:

First of all, we need to import math that is like call the library to come here (we need it, because it contents the functions). After that we write at the beginnig the functions we want. In this case I didn’t know how to code cube root, but remember that if we raise a number to one third it’s the same, so that’s what I did. We write def and the function. Then, in the next line what do you want it returns.

To continue, we start with our main code. We save what the user will introduce like an int and we are going to call it “x“.What about if the user enters a negative number? Well, I decided to send him a message, but if not, I continue with my programm (that is what we are evaluating in the if-else).

Now, to print the roots, first we have to make the operations, that is what we are doing in the z and y declaration. Finally, we just write a message to announce what we are doing plus the result.

And it’s ready It runs like this:

# Quiz 3

--Originally published at Site Title

Para este Quiz se debería de realizar un programa que integrara las siguientes funciones:

def square_root(x):  // returns the square root of x (float)

def cube_root(x): // returns the cube root of x (float)

Primero empezamos por definir las funciones:

En este caso observamos que primero debemos importar de math la función sqrt para que la raíz cuadrada funcione. Luego creamos las funciones y describimos sus procesos para que la computadora sepa que actividad debe realizar en cada caso.

Luego colocamos un #main program below para mostrarle a la máquina que este es el programa que va a ejecutar. Pedimos el número y con las funciones ya definidas tan sólo las desplegamos en el resultado. Tambien debemos cuidar que los números negativos no tienen raíz cuadrada, debido a ello añadimos un if dónde si el número ingresado es negativo le indicamos al usuario que la raíz cuadrada no existe.

El programa en ejecución

Para la realización de este programa me basé basicamente en contenido visto en clase (enseñanzas del profesor)

# Quiz Week 3

--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 square_root(x):  // returns the square root of x (float)
• def cube_root(x): // returns the cube root of x (float)

You should make a main routine that asks the user for a number and then calls your functions to calculate the square and cube roots of that number and prints them out.

This is my code:

In another post I’ll explain everything that went on this code.