Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sys import argv, exit # import argv and exit functions
- def to_f(c): # Convert celsius to ferinheight
- temp = (c * 9/5) + 32
- return temp
- def to_c(f): # Convert ferinheight to celsius
- temp = (f - 32) * 5/9
- return temp
- def main():
- args = argv[1:] # Creates an argument list omitting the omitting the [0] element
- if len(argv) < 2: exit(1) # If less than two arguments
- if args[0] == '-f': # If the first argument is -f
- print args[1], 'ferinheight is', str(to_c(int(args[1]))), 'celsius'
- elif args[0] == '-c': # If the first argument is -c
- print args[1], 'celsius is', str(to_f(int(args[1]))), 'ferinheight'
- else: exit(1)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement