February 13th, 2013, 08:20 PM

Python question (about strings)
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!!!
February 13th, 2013, 08:35 PM

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 /.
February 13th, 2013, 09:07 PM

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.
PHP FAQ
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
February 13th, 2013, 09:35 PM

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.
[code]
Code tags[/code] are essential for python code and Makefiles!