[How to Solve] Python TypeError: ‘int‘ object is not subscriptable

The title is the teacher’s lesson, which is adapted from the python language design basis of Songtian teacher of Beijing Institute of technology, page 4.7, 121

Please modify example 5: body mass index BMI with exception handling, so that it can receive and process any input from the user

while True:
try:
Height, weight = Eval (input (“please input height (m) and weight (kg) [separated by commas]:”)
0         bmi = weight/pow(height,2)
Print (“BMI value is: {. 2F}”. Format (BMI))
0         if height > 3:
if h[:-1].isinstance():
Print (“height value is {. 2F}”. Format (height))
0                 break
elif weight > 150:
if   w[:-1].isinstance():
Print (“body weight value is {. 2F}”. Format (weight))
0                 break
except NameError:
Print (“input error, please input correct information”)
the     else:
Print (“no exception occurred”)
finally:
Print (“complete”)

The cause of the error is an operation on an object that cannot be operated on

The original errors were height [: – 1]. Isinstance and weight [: – 1]. Isinstance, which were changed to h and W

Please input height (m) and weight (kg) [comma separated]: 4,85
BMI value: 5.31
input error, please input correct information
complete
please input height (m) and weight (kg) [comma separated]: 1.85,85
BMI value: 24.84
no abnormality
complete
please input height (m) and weight (kg) [comma separated]: 1.85, 200
BMI value: 58.44
input error, please input correct information
complete
please input height (m) and weight (kg) [separated by commas]:


Read More: