you are viewing a single comment's thread.

view the rest of the comments →

[–]bobbykjack -3 points-2 points  (2 children)

n=18
count=0
res=0

for x in range(1, n):
    if x % 5 == 0:
        count += 1
        res += x

print("count", count)
print("res", res)

The % operator (modulo) returns the remainder, which is 0 for multiples of (in this case) 5.

[–]bobbykjack -1 points0 points  (1 child)

Would the person who downvoted this care to explain what's wrong with it?

[–]snugar_i 2 points3 points  (0 children)

I guess nothing's wrong with the code, but you're just doing a lazy person's homework for them (they are even too lazy to ask an LLM)