[Python] TypeError: 'list' object cannot be interpreted as an integer

Discussão em 'Python' iniciado por Stack, Março 6, 2025.

  1. Stack

    Stack Membro Participativo

    The playSound function is taking a list of integers, and is going to play a sound for every different number. So if one of the numbers in the list is 1, 1 has a designated sound that it will play.

    def userNum(iterations):
    myList = []
    for i in range(iterations):
    a = int(input("Enter a number for sound: "))
    myList.append(a)
    return myList
    print(myList)

    def playSound(myList):
    for i in range(myList):
    if i == 1:
    winsound.PlaySound("SystemExit", winsound.SND_ALIAS)


    I am getting this error:

    TypeError: 'list' object cannot be interpreted as an integer


    I have tried a few ways to convert the list to integers. I am not too sure what I need to change. I am sure that there is a more efficient way of doing this. Any help would be very greatly appreciated.

    Continue reading...

Compartilhe esta Página