Created
February 20, 2015 09:35
-
-
Save ejmurray/c332e0292f37899ae6c5 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. | |
""" | |
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 hyppotenusealt(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) | |
hyppotenusealt(3, 4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment