hello
this page will be focused on some programming challenges on Project Euler
[click to open Project Euler's site]so
this question is a basic example to show off loops and the modulus operator
below is an example of a solution in JS
let total=0;
for (let i; i<1000; i++) {
if (i%3 || i%5) {
total += i;
}
}
console.log(total);
in python, ive done some work trying to get the code as small as possible
my main goals was to have the entirety of the code, including output, be a single line
print(sum([i for i in range(1000) if i%3==0 or i%5==0]))
the single line of code above starts with print, we just print whatever value is inside
then we are taking the sum of something
the something we are taking the sum of is a list created using List Comprehension
[more on list comprehension can be seen here]this lets us loop and run functions inline to create a list
our list is everything from 0 to 999 that passes the if statement
the if statement simply returns true when i is a multiple of 3 or 5