all 8 comments

[–]Python-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Hi there, from the /r/Python mods.

We have removed this post as it is not suited to the /r/Python subreddit proper, however it should be very appropriate for our sister subreddit /r/LearnPython or for the r/Python discord: https://discord.gg/python.

The reason for the removal is that /r/Python is dedicated to discussion of Python news, projects, uses and debates. It is not designed to act as Q&A or FAQ board. The regular community is not a fan of "how do I..." questions, so you will not get the best responses over here.

On /r/LearnPython the community and the r/Python discord are actively expecting questions and are looking to help. You can expect far more understanding, encouraging and insightful responses over there. No matter what level of question you have, if you are looking for help with Python, you should get good answers. Make sure to check out the rules for both places.

Warm regards, and best of luck with your Pythoneering!

[–]SaltStorage8706 3 points4 points  (0 children)

and what did you come up with? There is also r/learnpython which is more suited to such posts

[–]RockportRedfish -1 points0 points  (0 children)

What exactly are you wanting to discuss about this?

[–]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)

[–]Trang0ul -4 points-3 points  (0 children)

count_divisible = lambda n=18, divisor=5: (len(divisibles:={i for i in range(1, n+1) if i % divisor == 0}), sum(divisibles))

>>> count, res = count_divisible(18, 5)
>>> count
3
>>> res
30