Quiz W3 – Functions

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.

quiz3

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.

Leave a comment