Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
February 13th, 2013, 08:20 PM
 ltcy
Registered User

Join Date: Feb 2013
Posts: 3
Time spent in forums: 57 m 31 sec
Reputation 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
February 13th, 2013, 08:35 PM
 Nyktos
Contributing User

Join Date: Dec 2012
Posts: 114
Time spent in forums: 1 Day 11 h 54 m 6 sec
Reputation Power: 3
Quote:
 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
February 13th, 2013, 09:07 PM
 E-Oreo
Lost in code

Join Date: Dec 2004
Posts: 8,233
Time spent in forums: 2 Months 2 Days 20 h 11 m 10 sec
Reputation 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
How to program a basic, secure login system using PHP

Quote:
 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

#4
February 13th, 2013, 09:35 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,217
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 35 m 4 sec
Reputation Power: 455
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!

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Python question (about strings)