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

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    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!!!
  2. #2
  3. 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 /.
  4. #3
  5. 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.
    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
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,955
    Rep Power
    481
    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!

IMN logo majestic logo threadwatch logo seochat tools logo