Skip to content

Commit 8994f56

Browse files
authored
Merge pull request #842 from rshpeley/patch-2
Arithmetic on the Command Line for 12-cmdline.md suggestions
2 parents fc32430 + 5173005 commit 8994f56

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

_episodes/12-cmdline.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,25 +666,25 @@ the program now does everything we set out to do.
666666
667667
> ## Arithmetic on the Command Line
668668
>
669-
> Write a command-line program that does addition and subtraction:
669+
> Write a Python program that adds, subtracts, multiplies, or divides two numbers provided on the command line:
670670
>
671671
> ~~~
672-
> $ python arith.py add 1 2
672+
> $ python arith.py --add 1 2
673673
> ~~~
674674
> {: .language-bash}
675675
>
676676
> ~~~
677-
> 3
677+
> 3.0
678678
> ~~~
679679
> {: .output}
680680
>
681681
> ~~~
682-
> $ python arith.py subtract 3 4
682+
> $ python arith.py --subtract 3 4
683683
> ~~~
684684
> {: .language-bash}
685685
>
686686
> ~~~
687-
> -1
687+
> -1.0
688688
> ~~~
689689
> {: .output}
690690
>
@@ -696,8 +696,8 @@ the program now does everything we set out to do.
696696
> > assert len(sys.argv) == 4, 'Need exactly 3 arguments'
697697
> >
698698
> > operator = sys.argv[1]
699-
> > assert operator in ['add', 'subtract', 'multiply', 'divide'], \
700-
> > 'Operator is not one of add, subtract, multiply, or divide: bailing out'
699+
> > assert operator in ['--add', '--subtract', '--multiply', '--divide'], \
700+
> > 'Operator is not one of --add, --subtract, --multiply, or --divide: bailing out'
701701
> > try:
702702
> > operand1, operand2 = float(sys.argv[2]), float(sys.argv[3])
703703
> > except ValueError:

code/arith.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ def main():
55
assert len(sys.argv) == 4, 'Need exactly 3 arguments'
66

77
operator = sys.argv[1]
8-
assert operator in ['add', 'subtract', 'multiply', 'divide'], (
9-
'Operator is not one of add, subtract, multiply, or divide: '
8+
assert operator in ['--add', '--subtract', '--multiply', '--divide'], (
9+
'Operator is not one of --add, --subtract, --multiply, or --divide: '
1010
'bailing out')
1111
try:
1212
operand1, operand2 = float(sys.argv[2]), float(sys.argv[3])
@@ -19,13 +19,13 @@ def main():
1919

2020
def do_arithmetic(operand1, operator, operand2):
2121

22-
if operator == 'add':
22+
if operator == '--add':
2323
value = operand1 + operand2
24-
elif operator == 'subtract':
24+
elif operator == '--subtract':
2525
value = operand1 - operand2
26-
elif operator == 'multiply':
26+
elif operator == '--multiply':
2727
value = operand1 * operand2
28-
elif operator == 'divide':
28+
elif operator == '--divide':
2929
value = operand1 / operand2
3030
print(value)
3131

0 commit comments

Comments
 (0)