I recently posted a question about splitting a string when a character is instanced. I have come up with the following code to calculate cartesian coordinates. However, I am getting the error - 'TypeError: 'bool' object is unsubscriptable' -. How do I fix this?
add_x = "s1"
add_y = "a3"
sample = ("0-0")
coordslst = sample.split('-')
user_coordinate_x = coordslst[0]
user_coordinate_y = coordslst[1]
if (add_x.split('s'))[0] == ("s"):
new_coordinate_x = str(int(user_coordinate_x) - int((add_x.split('a', 's'))[1]))
elif (add_x[0] == ('a'))[0] == ("a"):
new_coordinate_x = str(int(user_coordinate_x) + int((add_x.split('a', 's'))[1]))
if (add_y.split('s'))[0] == ("s"):
new_coordinate_y = str(int(user_coordinate_y) - int((add_y.split('a', 's'))[1]))
elif (add_y.split('a'))[0] == ("a"):
new_coordinate_y = str(int(user_coordinate_y) + int((add_y.split('a', 's'))[1]))
new_coordinates = new_coordinate_x + "-" + new_coordinate_y
print new_coordinates
It's this line here
elif (add_x[0] == ('a'))[0]:
(add_x[0] == ('a')) returns False
and you are trying to access it's first element like False[0], which doesn't make sense.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With