Answers
2.4. Answers#
Solution to Exercise 2.1
1.0
(float)1
(int)TypeError
sincex/x
is a float and we cannot index an array using a float. Try usingz[x//x]
orz[int(x/x)]
instead."5555555555"
(string)[10, 20, 10, 20, 10, 20, ... , 10, 20]
(list)TypeError
since 10. is a float and we cannot use the operator*
with a list and a float. First convert to a float.array(100, 200)
(Numpy array)TypeError
since floats and strings cannot be added. Convertw
to an int or float first e.g.y + int(w)
.array([100, 400])
Numpy performs elementwise multiplication