Created
February 20, 2015 09:37
-
-
Save ejmurray/aef6f3681908bd1a9d07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# encoding: utf-8 | |
""" | |
Function which calculates the hypotenuse of a right angled triangle | |
using two different methods. | |
Exercise 6.2 Think Python | |
""" | |
import math | |
__author__ = 'Ernest' | |
def hypotenuse(a, b): | |
""" | |
A function that calculated the hypotenuse of a right angled triangle | |
:param a: any number | |
:param b: any number | |
:return: hypotenuse | |
""" | |
asquared = a**2 | |
bsquared = b**2 | |
sumsquared = asquared + bsquared | |
# print ('squared values and sum: '), sumsquared | |
result = math.sqrt(sumsquared) | |
print('The hypotenuse of the right angled triangle is: '), result | |
return result | |
def hypotenusealt(a, b): | |
""" | |
Using the built in function fo the hypotenuse | |
:param a: | |
:param b: | |
:return: | |
""" | |
result2 = math.hypot(a, b) | |
print('Here is the result using the built in function: '), result2 | |
return result2 | |
hypotenuse(3, 4) | |
hypotenusealt(3, 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment