import sys def hello(a,b): print "hello and that's your sum:", a + b if __name__ == "__main__": a = int(sys.argv[1]) b = int(sys.argv[2]) hello(a, b) # If you type : py main.py 1 5 # It should give you "hello and that's your sum:6"
Here is what the above code is Doing:
1. It defines a function called hello that takes two arguments, a and b.
2. It prints out “hello and that’s your sum:”, and then the sum of a and b.
3. It checks if the __name__ variable is equal to “__main__”.
4. If it is, it sets a to the first command line argument, and b to the second.
5. It calls the hello function with a and b as arguments.