dimanche 3 novembre 2019

IndexError: string index out of range. In Python. Newbie

The error message I receive:

trans = latin[latn] + eng[letter]
Line 24 IndexError: string index out of range

My code:

eng = input(" English ----- ")
latin = "mustang"
word = len(eng)
index = len(latin)
letter = 0
latn = 0
trans = ""
while eng != trans:
    if word <= 7:
        combine = "".join(i for j in zip(latin, eng) for i in j)
        print(combine + "bison") 
    if word >= 7:
        while letter <= word:
            trans = latin[latn] + eng[letter]
            latn = latn + 1
            letter = letter + 1
        print(trans + "bison")
        if word > index:
            multi = word // index
            latin = latin * multi
    eng = input(" English ----- ")
    if eng == "":
        print()

I don't get why I keep getting this error. I had a range in the same line as the error before, so I thought it would only work with a while statement.

Aucun commentaire:

Enregistrer un commentaire