Cannot figure out what is causing this error in Python
Question:
I keep getting this TypeError: ‘int’ object is not subscriptable error. I’m stuck.
I’ve tried taking away and adding str and int in different places but nothing has worked at all.
Answers:
Try this code.
def midform(point1, point2):
x = (point1[0] + point2[0])/2
y = (point1[1] + point2[1])/2
print("Midpoint X:", x, "Y:", y)
Error: because point1[0]
is in your case an integer and you try indexing on int.
I keep getting this TypeError: ‘int’ object is not subscriptable error. I’m stuck.
I’ve tried taking away and adding str and int in different places but nothing has worked at all.
Try this code.
def midform(point1, point2):
x = (point1[0] + point2[0])/2
y = (point1[1] + point2[1])/2
print("Midpoint X:", x, "Y:", y)
Error: because point1[0]
is in your case an integer and you try indexing on int.