Guest User

Untitled

a guest
Jan 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import math, sys # Importing modules.
  4.  
  5. def formatresult(res): # Define function. Remember colon!
  6. """This is the documentation for a function."""
  7. return "The result is %f" % res # Percentage for formating
  8.  
  9. if len(sys.argv) < 3: # Conditionals should be indended
  10. print("Too few input argument")
  11. elif len(sys.argv) > 10: # Not 'elsif' or 'elseif'
  12. print("Too many input argument")
  13. else:
  14. res = 0; # Semicolon not necessary. Considered bad style
  15. for n in range(1, len(sys.argv)): # Not first element in loop
  16. try: res += float(sys.argv[n]) # One-liner: no identation
  17. except: pass # One-liner!
  18. print(formatresult(res))
Add Comment
Please, Sign In to add comment