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?
try divisors = divisors + (i, )
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.
Ah... lol. true.
Join our real-time social learning platform and learn together with your friends!