Function Practice Homework 1

Implement and test all of the following functions in a single script.

1. Create a function that prints your name. It should have no parameters and be called MyName.

2. Create a function that returns the volume of a icosahedron of radius r. Call it icosa_vol(r)

3. Write a function called Poly3(a,b,c,d,x) that will evaluate a cubic polynomial given the coefficients a,b,a,and d as well as the value of x.

4.  Write a function called hypotenuse(a,b) that will return the length of the hypotenuse of a right triangle having sides a and b.  The variables a and b are integer and the answer is float.

Test the above programs using the following instruction sequence.

#Place all the functions in one file and document each function and put your name at the top which the data and the title “A study in functions”.  Run the program and print out the program(source) and the output on one page.

[def the four functions here]

x =hypotenuse(3,4)

z=hypotenuse(5,18)

y=Poly3(1,2,-11,-12,x);

print ‘The value of x is ‘,x

print “The value of y is “,y

print “The value of z is “,z

print “The volume of the icosahedron is “,icosa_vol(5)

print MyName, MyName, MyName   <<<—  This is an error.  Use the following command instead.

MyName, MyName, MyName

Comments are closed.