File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ '''
2+ Python 3
3+ Takes two numbers given as command line arguments, and prints their sum
4+ '''
5+
6+ # The sys library lets us access command line arguments
7+ import sys
8+
9+
10+ # This line ensures the code will only run if the file is launched as a program - not if it is imported as a module
11+ if __name__ == '__main__' :
12+
13+ # The sys.argv array contains the command passed to Python.
14+ # The first element is the name of the program, while the following elements are command-line arguments.
15+ # The float function converts the argument, which is a string, to a decimal number.
16+ x = float (sys .argv [1 ])
17+ y = float (sys .argv [2 ])
18+
19+ # To get the sum of two numbers, we simply use the + operator
20+ sum = x + y
21+
22+ # Finally, we print our result to the console
23+ print (sum )
You can’t perform that action at this time.
0 commit comments