Skip to content

Instantly share code, notes, and snippets.

@fnielsen
Created September 7, 2012 17:35
Show Gist options
  • Save fnielsen/3668027 to your computer and use it in GitHub Desktop.
Save fnielsen/3668027 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import math, sys # Importing modules.
def formatresult(res): # Define function. Remember colon!
"""This is the documentation for a function."""
return "The result is %f" % res # Percentage for formating
if len(sys.argv) < 3: # Conditionals should be indended
print("Too few input argument")
elif len(sys.argv) > 10: # Not 'elsif' or 'elseif'
print("Too many input argument")
else:
res = 0; # Semicolon not necessary. Considered bad style
for n in range(1, len(sys.argv)): # Not first element in loop
try: res += float(sys.argv[n]) # One-liner: no identation
except: pass # One-liner!
print(formatresult(res))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment