• 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,240 points

Related questions

0 votes
1 answer 19 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 10 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 5.7k points
1 vote
1 answer 35 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
1 vote
1 answer 99 views
Problem: I am doing a course on python programming language. As a begginer I have to do a lot of programming practice and some of them are very confusing. Today I wrote a code to do some counting problems in python. The code I wrote is: def count(serial, totals): ... is not iterable What is the problem in my programm and what should I do now. Can anyone explain me this error. Thanks in advance.
asked Apr 4, 2020 LizzyM 6.1k points
0 votes
1 answer 44 views
Problem: Django I have the following models: class Group(models.Model): name = models.CharField(max_length=100) parent_group = models.ManyToManyField("self", blank=True) def __unicode__(self): return self.name class Block(models.Model): name = models.CharField(max_length= ... return blocks But b1.group.block_set returns me a RelatedManager object that cannot be repeated. What to do? What's wrong?
asked Dec 13, 2020 sasha 5.3k points
2 votes
2 answers 1K views
Problem: Hello Kodlogs, I am a new student of Python programming. I am learning the language from YouTube and other voluntary websites and solving basic level problems from them. I&rsquo;ve written a piece of python program that is not working properly and throws back an error ... please point out the issue and help me to fix it? I appreciate your effort and valuable time very much. Thanks a ton.
asked Apr 26, 2020 Gavin 15.3k points
2 votes
1 answer 142 views
Problem: Hello Kodlogs, I am a new fellow in this forum. I joined the forum because of you people. I think you guys are awesome and pretty much helpful to each other. Well, let me come to the point now. I have a python list in my program. I want to iterate ... (data): for item in data: print(item) I am looking forward to hearing from you. Thanks for your valuable time and kind concern. Thanks.
asked Apr 25, 2020 Gavin 15.3k points
1 vote
1 answer 1.5K views
Problem: Hello guys, I have a chunk of python code where I am trying to extract all the links from a particular website. For that, I am using selenium.webdriver. But the program is not retrieving the links from that website as I am expecting. Instead of that, it is ... problem? I really appreciate your help in this regard. It took already much times from me but couldn't find any way. Thanks a lot.
asked Apr 21, 2020 Gavin 15.3k points
1 vote
1 answer 356 views
Problem: When I run or compile this program import urllib2 import time import datetime HolaAndre = 'HUA','WALT','NOKA','CMG','EVAL','DARZ','SYM' def BackData(stock): try: print 'Still pulling',stock print str(datetime.datetime.fromtimestamp(time. ... BackData(eachStock) It shows me the following error main loop 'builtin_function_or_method' object is not iterable What is the problem please help me.
asked Apr 5, 2020 LizzyM 6.1k points
1 vote
1 answer 1.2K 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