Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 18 Online
OpenStudy (anonymous):

Watching Video Lecture 3... I'm trying to find the divisors using the program with the tuple as shown. I'm using the exact code as shown in the lecture, but I keep getting an error from the line divisors = divisors + (i) "TypeError: can only concatenate tuple (not "int") to tuple. Why does the code work in the lecture but not for me?

OpenStudy (anonymous):

try divisors = divisors + (i, )

OpenStudy (anonymous):

Ah, there you're mistaken. The code 'worked' cuz Prof. Grimson didn't use a tuple, he used a list. This is the code from the handout: x = 100 divisors = [] for i in range(1, x): if x % i == 0: divisors = divisors + [i] As you can see, they all have square brackets, indicating that they're lists, not tuples. Lists are mutable, so it's easy to modify them. Tuples on the other hand, are immutable. You can only concatenate them, and you can only do so with another tuple.

OpenStudy (anonymous):

Ah... lol. true.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Breathless: Spooky witch but cute
4 hours ago 3 Replies 0 Medals
Arriyanalol: help
4 hours ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
1 day ago 5 Replies 4 Medals
Jaded012023: Please tell me what you all think of this song
7 hours ago 6 Replies 1 Medal
Arriyanalol: bro how
7 hours ago 2 Replies 3 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
1 day ago 12 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!