martes, 7 de marzo de 2017

QUIZ 4 Minimum and Squares

Quiz 4
For this quiz we were supposed to create 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
For this quiz 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.
For this as you can see in the pictures below, you must first import math, so you use the "math.pow" function.
Defining a function is pretty simple, you just need to name it, state the variables, and tell it what to do.



As always, here´s my code so you can check it out:
import math

def minimum_three(x,y,z):
    return min (x,y,z)
def sum_squares (x,y,z):
    return math.pow(x,2) + math.pow(y,2) + math.pow(z,2)

x=float(input("type a number:"))
y=float(input("type a number:"))
z=float(input("type a number:"))
r=minimum_three(x,y,z)
s=sum_squares(x,y,z)

print ("the minimum of the three numbers is:", r)
print ("the sum of squares of the three numbers is:", s)

For help with functions, I used the "How to think like a computer scientist" book.

No hay comentarios:

Publicar un comentario