Question
Write a function moreOdds that accepts one argument, a list of integers. The function then returns a bool that indicates whether the list contains (strictly) more odd numbers than even numbers. Sample output:
>>> moreOdds( [2,3,4,5,7] )
TrueAnswer:
def moreOdds(lst):
odds = 0
evens = 0
for n in lst:
if n % 2 == 0:
evens += 1
else:
odds += 1
if odds > evens:
return True
return False
Comments