i = 0
num = 0
while i <= 1000:
if i % 3 and i % 5 == 0:
num + i = num <--- Adding Up Numbers Divisable by 3 & 5...
i += 1
print num
Error:* can’t assign to operator (line 5)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Are you sure you don’t want:
or equivalently:
?
Note that this can be done a little easier using
sum,rangeand a generator expression:If you’re planning on running this code on only python 2.x, you can change
rangetoxrangein the above expression. Also, when reading other people’s code, you’ll sometimes seeif x % 3 == 0written asif not x % 3in this type of context, but I prefer the first version (it seems a little more explicit to me).