-
Notifications
You must be signed in to change notification settings - Fork 0
/
floatops.py
33 lines (26 loc) · 1023 Bytes
/
floatops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#-----------------------------------------------------------------------
# floatops.py
#-----------------------------------------------------------------------
import stdlib.stdio as stdio
import sys
# Accept two floats a and b as command-line arguments. Use them
# to illustrate float operators. Write the results to standard output.
a = float(sys.argv[1])
b = float(sys.argv[2])
total = a + b
diff = a - b
prod = a * b
quot = a / b
exp = a ** b
stdio.writeln(str(a) + ' + ' + str(b) + ' = ' + str(total))
stdio.writeln(str(a) + ' - ' + str(b) + ' = ' + str(diff))
stdio.writeln(str(a) + ' * ' + str(b) + ' = ' + str(prod))
stdio.writeln(str(a) + ' / ' + str(b) + ' = ' + str(quot))
stdio.writeln(str(a) + ' ** ' + str(b) + ' = ' + str(exp))
#-----------------------------------------------------------------------
# python floatops.py 123.456 78.9
# 123.456 + 78.9 = 202.356
# 123.456 - 78.9 = 44.556
# 123.456 * 78.9 = 9740.6784
# 123.456 / 78.9 = 1.5647148289
# 123.456 ** 78.9 = 1.04788279167e+165