尝试针对表测试输入时出现此错误

时间:2020-08-05 03:03:41

标签: python

运行此代码时出现此错误

line 101, in seventh_question
    if int(weight) >= heightandweight[height][2]:
KeyError: 187

代码:

def seventh_question():

       height = int(input("\nWhat is your height in centimeters? "))

       if height < 147:
             height = 147
    
       if height >= 193:
             height = 193

       weight = int(input("\nWhat is your weight in Kg's? "))

       if int(weight) >= heightandweight[height][2]:
             return 3

       if int(weight) >= heightandweight[height][1]:
             return 2

       if int(weight) >= heightandweight[height][0]:
             return 1

       with open("height_weight.json") as f:
       heightandweight = json.load(f)
       f.close()

0 个答案:

没有答案