Five numbers are given below. Keeping them in that same order, compute a single result with Python addition, multiplication, subtraction, and division, respectively.
Put another way--add the first and second numbers, multiply the second and third numbers, subtract the third and fourth numbers, and divide the fourth and fifth numbers. Don't use any parentheses; let order of operations take care of things. Do this in a single statement, and store the result in the result
variable below.
In [ ]:
n1 = 0.4589
n2 = 13
n3 = -59
n4 = 8.43333333
n5 = 2.1
result = -1
### BEGIN SOLUTION
### END SOLUTION
In [ ]:
import numpy as np
np.testing.assert_allclose(result, -770.5569730142857)
In [ ]:
n1 = 0.4589
n2 = 13
n3 = -59
n4 = 8.43333333
n5 = 2.1
result = -1
### BEGIN SOLUTION
### END SOLUTION
In [ ]:
import numpy as np
np.testing.assert_allclose(result, -432.1802333119699)
In [ ]:
n1 = 0.4589
n2 = 13
n3 = -59
n4 = 8.43333333
n5 = 2.1
result = -1
### BEGIN SOLUTION
### END SOLUTION
In [ ]:
assert result == -435.5
In [ ]:
n1 = 20344983945038.48374839
n2 = 984374.783894273
quotient = -1
### BEGIN SOLUTION
### END SOLUTION
In [ ]:
import numpy as np
np.testing.assert_allclose(quotient, 20667924.735487375)
You've seen in lecture how, when two numbers in Python are divided, their result is a float. What if you really wanted the output of division to be an integer? See if you can make that happen by modifying the following single line of code.
(You are not allowed to add any numbers or additional lines of code!)
In [ ]:
integer_quotient = 32 / 16
In [ ]:
assert type(integer_quotient) == int