Question #75360

2. 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] )
True
1

Expert's answer

2018-04-03T10:53:57-0400

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] )
True

Answer:

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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS