Skip to content

Commit e760767

Browse files
Merge pull request #8 from Lagostra/master
Added SimpleAddition implementation
2 parents 89bbd11 + 1e214a7 commit e760767

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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)

0 commit comments

Comments
 (0)