0

Why it doesnt work? exercise: Find the sum of all the multiples of 3 or 5 below 1000.

y = [] x = [] a = 0 result = 0 for i in range(1001): x.append(i) while a < 1001: if x[a] % 5 == 0 or x[a] % 3 == 0: y.append(x[a]) a += 1 a = 0 while a < len(y) or y == len(y): result = result + y[a] a += 1 print (result)

20th Sep 2020, 11:04 AM
ItzNekS
ItzNekS - avatar
4 ответов
+ 4
this code works, the problem is you include 1000. it says below 1000 so max is 999.
20th Sep 2020, 11:11 AM
Yahya Bey
Yahya Bey - avatar
+ 4
ItzNekS , it's not quiet clear what problem you have, except the ones that Yahya Bey mentioned. What problem do you encounter?
20th Sep 2020, 1:40 PM
Lothar
Lothar - avatar
+ 3
I think your code could be a lot shorter if you only want to calculate result.
20th Sep 2020, 11:41 AM
Paul
Paul - avatar
0
thank you. my bad :v
20th Sep 2020, 11:15 AM
ItzNekS
ItzNekS - avatar