1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2013
Posts
3
Rep Power
0

Question :
Assume that the inputs to this funciton are two integer numbers. This function should return a boolean value. The value to be returned should be True if the remainder of dividing num by div is even and it should return False otherwise.

and my code :

divide_num = div/num
if (divide_num%2 == 0):
result = True
else:
result = False
return result

the code doesn't work out, can someone please tell me what's wrong with my code??
THanks!!!
2. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Dec 2012
Posts
114
Rep Power
3
Originally Posted by ltcy
Assume that the inputs to this funciton are two integer numbers. This function should return a boolean value. The value to be returned should be True if the remainder of dividing num by div is even and it should return False otherwise.
What operator gives you the remainder? It's not /.
3. No Profile Picture
Lost in code
Devshed Supreme Being (6500+ posts)

Join Date
Dec 2004
Posts
8,316
Rep Power
7170
The operator used to get the remainder is not an operator commonly used outside of programming, but you're already using it in your code to check whether the value is odd or even.
4. Code:
```'''
1) you need a function.
2) you need to know the definition of numerator and divisor.
3) you need to know some of the python operators.
'''

def HomeWorkProblem4(numerator,divisor):  # this is a function definition
remainder = numerator % divisor   # % operator returns the remainder
return 0 == (remainder % 2)  # == computes Boolean result.```