+ 1
Help!
Given a number, I want to check if it is divisible for 3. IF I don't get an integer number I have to add n in order to get (number%3==0). How can I do that?thanks
7 Answers
+ 4
The Rocky number % 3 will return the remainder of division. So, it will return the value needed to add to the number in order to get number % 3 == 0 to be True.
if number % 3 == 0:
...
... # number is divisible by 3
else:
# number not divisible by 3
number += number % 3
# now number is divisible by 3
You could also set the remainder to a variable
number = int(input())
rem = number % 3
print(f"Adding {rem} to {number} makes it evenly divisible by 3")
+ 13
The Rocky read the guidelines of the community first.
https://www.sololearn.com/discuss/1316935/?ref=app
+ 11
please don't ask any homework question here :)
show ur attempt first.
+ 3
You are kidding me right? Your intervention is useless
+ 3
So what... What is missing? If u know how to help me that is fine otherwise you are wasting my time
+ 3
You are crazy... I just told you that I don't know how to do that!! I was thinking to increase the number by 1 in a while function that is all...
+ 2
The Rocky
The Tαrα°°â is correct first show your attempt if you have completed sololearn conditional statements lesson than you should do yourself if you have anything bug or problem in your code then tell us we wil help you