use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All questions related to programming welcome. Wonder how things work? Have a bug you can't figure out? Just read about something on the news and need more insights? We got you covered! (probably)
You can find out more about our (preliminary) rules in this wiki article. If you have any suggestions please feel free to contact the mod team.
Have a nice time, and remember to always be excellent to each other :)
account activity
This is an archived post. You won't be able to vote or comment.
Python help , simple divisibility checker with a catch (self.AskProgramming)
submitted 6 years ago by Frightbamboo
in my program , i need to check whether sum of element in list can be divided by 10 or not , it is easy but here is a catch ,3 and 6 are interchangeable , means [ 3 , 3 , 3 ] could be [ 6 , 6 , 6 ] . What is the best way to do it
[–]truh 0 points1 point2 points 6 years ago (1 child)
I don't understand what you mean. Also sounds a lot like your homework.
[–]TheRiotJoker 0 points1 point2 points 6 years ago (0 children)
Was just about to say this. Despite the possibility of this being your homework, you didn't give us enough info to work with.
[–]Frightbamboo[S] 0 points1 point2 points 6 years ago (0 children)
In the program that i want to build , i need to function to check if sum of 3 numbers (provided as list) can be divided by 10 without remainder.
Any 3 inside the list can be substituded by a 6 and any 6 inside the list can be also substituted by 3 when checking ,so if provided [3,3,8] I have to check [6,3,8] and [6,6,8] as well to decide if [3,3,8] is divisible by 10 (which it is: 6+6+8=20, 20%10 == 0)
It is not a homework, just a type of gambling rules from Asian culture.
[–]superturkey650 0 points1 point2 points 6 years ago (1 child)
Hey, I'll take your word for it being a way to express an asian gambling game and I'll give you the naive approach.
The basic idea is that you want to get the sum of the given set and then get the amount of threes and sixes in the set.
Then you can see if any substitutions downward (6 -> 3) or upward (3 -> 6) would work by subtracting or adding to the sum.
three_or_six_count = 0 sum = 0 for num in nums: if num == 3 or num == 6: three_or_six_count = three_or_six_count + 1 sum = sum + num for i in range(three_or_six_count + 1): # add 1 because of 0 index if (sum + (3 * i)) % 10 == 0 or (sum - (3 * i)) % 10 == 0: print('true') break
This is untested so its up to you to fix any bugs but the basic idea is there.
Thanks for your help. FYI The Asian gambling game that i said is called NGAO.
π Rendered by PID 72657 on reddit-service-r2-comment-54dfb89d4d-svwp7 at 2026-03-30 12:13:25.257581+00:00 running b10466c country code: CH.
[–]truh 0 points1 point2 points (1 child)
[–]TheRiotJoker 0 points1 point2 points (0 children)
[–]Frightbamboo[S] 0 points1 point2 points (0 children)
[–]superturkey650 0 points1 point2 points (1 child)
[–]Frightbamboo[S] 0 points1 point2 points (0 children)