Skip to content

Instantly share code, notes, and snippets.

@cdodd
Created September 5, 2013 12:28
Show Gist options
  • Save cdodd/6449450 to your computer and use it in GitHub Desktop.
Save cdodd/6449450 to your computer and use it in GitHub Desktop.
Alcohol by volume (ABV) calculator based on original and final beer gravity readings.
#!/usr/bin/python
import sys
# Get the original and final gravity from the commandline args
try:
og = float(sys.argv[1])
fg = float(sys.argv[2])
except IndexError:
print 'Usage %s <original gravity> <final gravity>' % sys.argv[0]
sys.exit(1)
# Calculate and print the ABV
abv = ((((1.05) * (og - fg)) / fg) / 0.79) * 100
print '%.1f%%' % abv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment