Skip to content

Instantly share code, notes, and snippets.

@Mause
Created March 31, 2014 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mause/9889202 to your computer and use it in GitHub Desktop.
Save Mause/9889202 to your computer and use it in GitHub Desktop.
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