Created
March 31, 2014 10:08
-
-
Save Mause/9889202 to your computer and use it in GitHub Desktop.
This file contains 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
import math | |
def area_of_circle(diameter): | |
return math.pi * (diameter / 2 ** 2) | |
def volume_of_pipe(inner_diameter, outer_diameter, length): | |
area_of_pipe_end = ( | |
area_of_circle(outer_diameter) - | |
area_of_circle(inner_diameter) | |
) | |
return length * area_of_pipe_end | |
def weight_of_pipe(inner_diameter, outer_diameter, length, mass_per_unit): | |
return ( | |
mass_per_unit * | |
volume_of_pipe(inner_diameter, outer_diameter, length) | |
) | |
def main(): | |
wop = weight_of_pipe( | |
inner_diameter=9, | |
outer_diameter=10, | |
length=50, | |
mass_per_unit=1 | |
) | |
# old (c-like) syntax | |
print('%.2f units' % wop) | |
# new syntax | |
print('{:.2f} units'.format(wop)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment