"IndexError: list index out of range"
Verfasst: Freitag 8. Juni 2012, 00:30
Hey Leute. Ich habe mal aus Neugier (bin neu mit Python) versucht, ein Skript zu schreiben, welches alle möglichen Kombinationen von den Buchstaben A-Z ausgibt (bis zu 3 Stellen, also "A bis Z", "A bis Z + A bis Z" und "A bis Z + A bis Z + A bis Z").
Es funktioniert soweit auch alles, bis auf einen Fehler ganz am Ende, sobald das Skript durchgelaufen ist.
Dieser Fehler erscheint wirklich erst ganz am Ende, sobald alle Kombinationen durchgelaufen sind (hier die Ausgabe: http://www.pastebin.com/bHRamh8x).
Der Quellcode:
Danke schon einmal für die Antworten und Entschuldigung, wenn ich was falsch gemacht habe. Ist mein erster Beitrag :/
Es funktioniert soweit auch alles, bis auf einen Fehler ganz am Ende, sobald das Skript durchgelaufen ist.
Code: Alles auswählen
Traceback (most recent call last):
File "C:/Users/Stefan/Desktop/Python/asdasd.py", line 42, in <module>
loop3(x,y)
File "C:/Users/Stefan/Desktop/Python/asdasd.py", line 22, in loop3
print atoz[x] + atoz[x2] + atoz[x3]
IndexError: list index out of rangeDer Quellcode:
Code: Alles auswählen
atoz = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
x = 0
x2 = 0
x3 = 0
y = 25
def loop1(x, y):
while x<y:
print atoz[x]
x += 1
def loop2(x, y):
while x<y:
print atoz[x] + atoz[x2]
x += 1
def loop3(x, y):
while x<y:
print atoz[x] + atoz[x2] + atoz[x3]
x += 1
loop1(x,y)
x = 0
while x2<y:
loop2(x,y)
x2+=1
x = 0
x2 = 0
while x3<y:
while x2<y:
loop3(x,y)
x2+=1
if x2==y:
x2=0
x3+=1