• Register
2 votes
1.5k views

Problem:

I am trying a run a program with a simple list object in my code. But it throwing the same error again and again. The error is: list object cannot be interpreted as an integer python.

I am attaching my code snippet below:

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

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

What could be the possible solution for this program? If possible figure the error, please.

Thanks

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

2 votes

Solution:

Every time you get the error from the compiler or the interpreter you should read it carefully. The error clearly says that you did something that’s the reason the interpreter couldn’t interpret the object as an Integer.

So, where are you wrong? The range() is expecting an integer argument, from which it will build a range of integers. You can’t put a list inside the range(), it can’t handle the list.

So, if you want to access the items in testList, loop over the list directly, just use:

>>> testList [1,2,3,4]
>>> for i in myList:
    print (i)

I hope you get the point. Thanks.

13 9 6
94,260 points

Related questions

0 votes
1 answer 22 views
22 views
Problem: What could be the possible solution for this program? If possible figure the error, please: list object cannot be interpreted as an integer python .
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
1 answer 203 views
0 votes
1 answer 61 views
61 views
Problem: TypeError: ‘float’ object cannot be interpreted as an integer Floating-point numbers are values that can contain a decimal point. Integers are whole numbers. It is common in programming for these two data types to be distinct.How to solve this error
asked Jan 6 Mashhoodch 13k points
2 votes
1 answer 69 views
69 views
Problem: I am a python newbee. I was trying some code : x = int(input("Input an Integer:")) res = [x] while x != 1: ---> for i in range(2, a): if x % i == 0: res.append(i) x = x / i break print(res) but this code shows some error ... did not compile. The error message is : TypeError: 'float' object cannot be interpreted as an integer Can any one tell me why am I getting this kind of error message?
asked Mar 23, 2020 LizzyM 6.1k points
0 votes
1 answer 2 views
2 views
Problem: I have a nested list with elements. I want the user to remove one list when he/she types an index of the list: So let's say the user types: "0" so ['elem', 'elem1', 'elem2'] will be deleted. 0 ['elem', 'elem1', 'elem2'] 1 ['elem3', 'elem4', ' ... (f"removed: {result}") Could someone please tell me what this error means? Does it mean that the index is not actually an int? How can I fix it?
asked 2 days ago anika11 32k points
0 votes
1 answer 12 views
12 views
Problem: Why this message keep shown to me :deprecationwarning: object of type <class 'float'> cannot be safely interpreted as an integer.
asked Mar 15 Wafa Abu Yousef 6.1k points
0 votes
1 answer 38 views
38 views
Problem: what the wrong thing that i did, make this happen ! numpy.float64' object cannot be interpreted as an integer.
asked Mar 6 Wafa Abu Yousef 6.1k points
1 vote
2 answers 2.9K views
2.9K views
Problem: Hello, I am not extremely versed in numpy, so I am not exactly sure what I am doing wrong. I got it to work with made-up data but I am not sure as to what it is not working with the data I put in. All I am trying to do is fit the data ... plt.ylabel('T') plt.legend() plt.show() The error I am getting is following below TypeError: 'numpy.float64' object cannot be interpreted as an integer
asked Mar 9, 2020 Gavin 15.3k points
0 votes
2 answers 1.3K views
1.3K views
Problem : I am facing following type error while trying to execute the Python program deprecationwarning: object of type <class 'float'> cannot be safely interpreted as an integer.
asked Nov 14, 2019 peterlaw 6.9k points