February 13th, 2013, 08:20 PM
Python question (about strings)
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
result = False
the code doesn't work out, can someone please tell me what's wrong with my code??
February 13th, 2013, 08:35 PM
What operator gives you the remainder? It's not /.
Originally Posted by ltcy
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.
February 13th, 2013, 09:35 PM
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] are essential for python code and Makefiles!