Difference between revisions of "Python Functions Assignment"
From WLCS
Line 5: | Line 5: | ||
== Resources == | == Resources == | ||
+ | * [[Media:PythonFunctions.pptx]] | ||
* [http://www.openbookproject.net/thinkcs/python/english2e/ch03.html HTTLACS: Ch 3 - Functions] | * [http://www.openbookproject.net/thinkcs/python/english2e/ch03.html HTTLACS: Ch 3 - Functions] | ||
* [http://www.openbookproject.net/thinkcs/python/english2e/ch05.html HTTLACS: Ch 5 - More Functions] | * [http://www.openbookproject.net/thinkcs/python/english2e/ch05.html HTTLACS: Ch 5 - More Functions] |
Revision as of 00:25, 13 November 2015
Objectives
- You will learn to define functions
- You will learn to call functions with input parameters
- You will learn to test the data returned by functions
Resources
Directions
Create a file name "functionsPractice.py". In your file, complete the following exercises:
- compare(a, b)
- Define a compare(a, b) function that returns 1 if a > b, 0 if a == b, and -1 if a < b
- Test your compare function with 3 different function calls. Make sure each gives you the expected result:
- compare(5, 4)
- compare(7, 7)
- compare(2, 3)
- hypotenuse(a, b)
- Define a hypotenuse(a, b) function that returns the length of the hypotenuse of a right triangle given the lengths of legs a and b
- Test your hypotenuse function with the following function calls. Make sure each gives you the expected result:
- hypotenuse(3, 4)
- hypotenuse(12, 5)
- hypotenuse(7, 24)
- f2c(t)
- Define a function named f2c(t) that converts the temperature parameter t from Fahrenheit to Celsius and returns it.
- If you don't remember the formula to convert, then look for it online!
- Create your own function calls that test the function
- c2f(t)
- Define a function named c2f(t) that converts the temperature parameter t from Celsius to Fahrenheit and returns it.
- If you don't remember the formula to convert, then look for it online!
- Create your own function calls that test the function