Created
September 7, 2012 17:35
-
-
Save fnielsen/3668027 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 | |
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