Concatenation of tuples
Normal text:
- I'm having some problems with coding on python 3.2.1. Actually I'm taking online lectures that 开发者_如何学编程are on python 2.5.
Here is the code:
x = 100 divisors = () for i in range(1,x): if x%i == 0: divisors = divisors + (i)
on running the program, following error appears:
divisors = divisors + (i) TypeError: can only concatenate tuple (not "int") to tuple
(1)
is not a tuple, its just a parenthesized expression. To make it a tuple, add a trailing comma, (1,)
Try to use this instead:
divisors.append(i)
Edit:
divisors = []
since you can't append on tuples.
精彩评论