Dict1 = {}#name
Dict2 = {}#grade
Dict3 = {}#special
def modified_grade():
return min(max(score*3/2-10, 0), 100)
def modified_spec_grade():
return min(max(score*5/2-20, 0), 100)
while True:
try:
n = input().split()
if n[0] == "i":
Dict1[int(n[1])] = n[2]
Dict2[int(n[1])] = int(n[3])
Dict3[int(n[1])] = int(n[4])
elif n[0] == "d" :
del Dict1[int(n[1])]
del Dict2[int(n[1])]
del Dict3[int(n[1])]
elif n[0] == "qg":
print(Dict2[int(n[1])])
elif n[0] == "qn":
print(Dict1[int(n[1])])
elif n[0] == "pg":
for key, value in sorted(Dict1.items()):
print(key, value, Dict2[key])
elif n[0] == "pm":
if n[4] == "1":
print("true")
elif inline[4] == 0:
print("bad")
except KeyError:
print("ID",n[1],"does not exist!")
except:
break
```如題,以下為我的程式碼,想請問第27行為什麼即使我input 為1,但輸出出來他卻說index error(下面print true 跟print bad是我先隨意打的一個指令)
ex. 我inpiut輸入:i 1 ryan 90 1 之後輸入pm 這時卻跳出index error 並告訴我 line 27: index out of range![https://ithelp.ithome.com.tw/upload/images/20210531/20137974n5HFGMhlgQ.png](https://ithelp.ithome.com.tw/upload/images/20210531/20137974n5HFGMhlgQ.png)
if n[4] == "1":
改成
if len(n)>4 and n[4] == "1":