Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env 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))
Add Comment
Please, Sign In to add comment