• Register
1 vote


What’s wrong with my codes? Can anybody please pull me up?

# add_list([1, 2, 3]) should return 6
# summarize([1, 2, 3]) should return "The sum of [1, 2, 3] is 6."
# Note: both functions will only take *one* argument each.

added_list = list()
sum = 0

def add_list(num):

def sum(num):
  sum = sum + add_list[num]

for num in 4:


Thanks in advance.




12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote


The problem created on that line when you wrote  for num in 4 : 

The ‘for’ operator works only for iterable data like list, string or other object containers. To avoid this error you may use a useful function called range function.
So, use

for num in range(4) :

instead of

for num in 4 :

Good day!

13 9 6
94,260 points

Related questions

0 votes
1 answer 6 views
problem: I need someone to understand the problem and solve the issue of typeerror: 'int' object is not iterable ?
asked Apr 5 ashik 14.6k points
0 votes
1 answer 25 views
Problem: I am looking to make a loop so that for each element in the list, it will get broken down into each of it's characters. For example, say the number 137 was in the list then it would be turned into [1,3,7]. Then I want to add these numbers together (I ... it). However, I keep getting the error message TypeError: 'int' object is not iterable when I try and run this. What am I doing wrong?
asked Feb 23 Mashhoodch 13k points
0 votes
1 answer 38 views
Problem: I am getting this error when trying to clear the JSON data, save it to another JSON file and finally convert it to a CSV file: for data1 to n: TypeError: int object is not repeated This is my code: import json import csv with open('leap_data.json') as f:     data = ... .writerow(data_1[0].keys()) for row in data_1:         output.writerow(row.values()) Please tell me how to get rid of it.
asked Nov 5, 2020 Han Li 710 points
0 votes
1 answer 82 views
Problem: The following error message is displayed: “Oops, try again. get_class_average([alice]) resulted in an error: ‘list’ object attribute ‘append’ is read-only” This is my code: lloyd = { "name": "Lloyd", "homework": [90.0, 97.0, 75.0, 92.0], "quizzes": [88.0, 40.0, 94.0], "tests": [75.0, 90.0] }
asked Feb 18 Mashhoodch 13k points
1 vote
1 answer 1.9K views
Problem: I am a beginner in python programming language. I tried to create a program to calculate my students avarage results so I wrote this code porter = { "name": "Porter", "homework": [90.0, 97.0, 75.0, 92.0], "quizzes": [88.0, 40.0, 94.0] ... try again. getclassaverage([porter]) resulted in an error: 'list' object attribute 'append' is read-only" Can anyone help me out to solve this problem?
asked Apr 5, 2020 LizzyM 6.1k points
0 votes
1 answer 4 views
Problem: int object is not iterable python error.
asked Mar 22 Dan phillip 4.8k points
1 vote
1 answer 5 views
Problem: Why I got the error : python int object is not iterable
asked Mar 20 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 26 views
Problem: I’m working on the count problem, and have come up with the following code: def count(sequence, item): found = 0 for i in len(sequence): if sequence[i] == item: found = found + 1 return found
asked Jan 22 Mashhoodch 13k points
0 votes
2 answers 31 views
Problem: hi I am studying and practicing JAVA these days .My passion is to understand things in a better way. I think it’s helping me a little bit more. Anyway, today I’ve come up with another question regarding Java conversion. I understand about iterable in java . i dont understand how to object not iterable in java.
asked Nov 2, 2020 Mashhoodch 13k points
1 vote
1 answer 39 views
Problem: Hello kodlogs, I am new to python I am trying to implement the basic program but dont know I am getting an error basically I am new to python language below is the code, this is all new to me as a belong to c language background so this is getting me ... line 1, in <module> TypeError: 'int' object is not iterable I don&rsquo;t know what I am doing wrong can someone please help this.
asked Jun 22, 2020 Gavin 15.3k points