TypeError: 'list' object cannot be interpreted as an integer in Python
playSound takes a list of integers and will play a sound for every single number. Thus, if one of the numbers in the list is - 1, then it 1has a certain 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 tried several ways to convert the list to integers. I'm not too sure what I need to change. I'm sure there is a more efficient way to do this. Any help would be greatly appreciated.
CopterJS Sep 05 2021
For me, I was getting this error because I needed to put the arrays in paratheses. In this case, the error is a little more complicated ...
concatenate((a, b))correct way
hope this helps.
majid gholipour Sep 05 2021
The answer is that you are passing your list as an input argument in
range()method that expects only an integer. Do not do this. Say instead
for i in myList.
Rahul Bagale Sep 05 2021
The error is this:
def playSound(myList): for i in range(myList): # <= myList is a list, not an integer
You cannot pass a list to range() that expects an integer. Most likely you intended to do:
def playSound(myList): for list_item in myList:
def playSound(myList): for i in range(len(myList)):
def playSound(myList): for i, list_item in enumerate(myList):