Skip to content

Commit 305b05d

Browse files
authored
Arithmetic on the Command Line for 12-cmdline.md suggestions
I think maybe a few clarifications could help this section. 1. The operators `add` and `subtract` maybe should have dashes like the actions in the previous example ==> `--add` and `--subtract`. This is just a matter of form, but may be more intuitive for some students. If so the operators would change in the problem and solution sections. 2. In the problem section the program output shows an expected integer result rather than the float cast used in the solution. The problem expected outputs should show float values to agree with the solution. 3. Giving a hint to the student that the solution may also include multiplication and division could be an incentive to try these operators as well. Of these, I think (2.) should be changed with the others being optional.
1 parent d051b23 commit 305b05d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

_episodes/12-cmdline.md

Lines changed: 6 additions & 6 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 command-line program that does addition and subtraction (you could also try multiplication and division operators):
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,7 +696,7 @@ 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'], \
699+
> > assert operator in ['--add', '--subtract', '--multiply', '--divide'], \
700700
> > '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])

0 commit comments

Comments
 (0)