У меня возникеєт ошибка в коде
name = [
"Pygame","PYgame","pYGame","pyGAme","pygAMe","pygaME","pygamE",
]
_name_ = len(name) - 1
play = True
while play:
pygame.display.set_caption(name[index])
if index == 0:
index += 1
turn = 1
elif turn == 1:
index += 1
elif index == _name_ :
index = 0
events = pygame.event.get()
Ошибка:
C:\Users\Gebruiker\Desktop\program\games>python3 DZ-1.py
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "DZ-1.py", line 26, in <module>
pygame.display.set_caption(name[index])
IndexError: list index out of range
C:\Users\Gebruiker\Desktop\program\games>
Ответы (1 шт):
Автор решения: Grundy
→ Ссылка
Проблема в строках
elif turn == 1:
index += 1
После того как turn стал равен единице на первой итерации, выполнение до
elif index == _name_ :
index = 0
не доходит и значение индеса никогда не сбрасывается.
Для решения эту проверку надо делать всегда.