英単語を複数形にするプログラムです
インプットは
7
box
photo
axis
dish
church
leaf
knife
です。
input_line = int(input())
words_spell=[list(input()) for i in range(input_line)]
for i in range(input_line):
#s, sh, ch, o, x は末尾にes
if words_spell[i][-1]=="s" or words_spell[i][-1]=="o" or words_spell[i][-1]=="x" or words_spell[i][-2]+words_spell[i][-1]=="sh" or words_spell[i][-2]+words_spell[i][-1]=="ch":
words_spell[i].append("es")
#末尾が f, fe のいずれかである英単語の末尾の f, fe を除き、末尾に ves を付ける
elif words_spell[i][-1]=="f" :
del words_spell[-1]
words_spell[i].append("ves")
elif words_spell[i][-1]+words_spell[i][-2]=="fe":
del words_spell[-2:-1]
words_spell[i].append("ves")
#末尾の1文字が y で、末尾から2文字目が a, i, u, e, o のいずれでもない英単語の末尾の y を除き、末尾に ies を付ける
elif words_spell[i][-1]=="y" and words_spell[i][-2]!="a" and words_spell[i][-2]!= "i" and words_spell[i][-2]!="u" and words_spell[i][-2]!="e" and words_spell[i][-2]!="o":
del words_spell[i][-1]
words_spell[i].append("ies")
#上のいずれの条件にも当てはまらない英単語の末尾には s を付ける
else:
words_spell[i].append("s")
エラーメッセージ
Traceback (most recent call last):
File "Main.py", line 12, in <module>
if words_spell[i][-1]=="s" or words_spell[i][-1]=="o" or words_spell[i][-1]=="x" or words_spell[i][-2]+words_spell[i][-1]=="sh" or words_spell[i][-2]+words_spell[i][-1]=="ch":
IndexError: list index out of range
エラーの理由がわかりません。
ちなみにもう提出済みなのでカンニングではありません
del words_spell[-1]
とかしてますけど、これってdel words_spell[i][-1]
ではないですかね。del words_spell[-2:-1]
もdel words_spell[i][-2:-1]
なのではないでしょうか。