forked from OpenGuide/Python-Guide-for-Beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request OpenGuide#8 from Lagostra/master
Added SimpleAddition implementation
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
''' | ||
Python 3 | ||
Takes two numbers given as command line arguments, and prints their sum | ||
''' | ||
|
||
# The sys library lets us access command line arguments | ||
import sys | ||
|
||
|
||
# This line ensures the code will only run if the file is launched as a program - not if it is imported as a module | ||
if __name__ == '__main__': | ||
|
||
# The sys.argv array contains the command passed to Python. | ||
# The first element is the name of the program, while the following elements are command-line arguments. | ||
# The float function converts the argument, which is a string, to a decimal number. | ||
x = float(sys.argv[1]) | ||
y = float(sys.argv[2]) | ||
|
||
# To get the sum of two numbers, we simply use the + operator | ||
sum = x + y | ||
|
||
# Finally, we print our result to the console | ||
print(sum) |