Advertisement
Guest User

Temperature Converter - Dr. H

a guest
Jul 11th, 2010
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. from sys import argv, exit # import argv and exit functions
  2.  
  3. def to_f(c): # Convert celsius to ferinheight
  4.     temp = (c * 9/5) + 32
  5.     return temp
  6.  
  7. def to_c(f): # Convert ferinheight to celsius
  8.     temp = (f - 32) * 5/9
  9.     return temp
  10.  
  11. def main():
  12.     args = argv[1:] # Creates an argument list omitting the omitting the [0] element
  13.     if len(argv) < 2: exit(1) # If less than two arguments
  14.     if args[0] == '-f': # If the first argument is -f
  15.         print args[1], 'ferinheight is', str(to_c(int(args[1]))), 'celsius'
  16.     elif args[0] == '-c': # If the first argument is -c
  17.         print args[1], 'celsius is', str(to_f(int(args[1]))), 'ferinheight'
  18.     else: exit(1)
  19.    
  20. if __name__ == '__main__':
  21.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement