python - Find the Number of even intergers in a sequence -
enter arbitrary sequence of integers @ keyboard, , prints number of positive integers user enters.
def find_even_count(): count = 0 x = raw_input("enter value, or q quit: ") while (x != "q") , (x > 0): num in x: if (int(x) % 2 == 0): count += 1 entry = raw_input("enter value, or q quit: ") return count
i have gotten far not working ideas?
if counting them entered there no need iterate.
def find_even_count(): count = 0 x = raw_input("enter value, or q quit: ") while (x != "q") , (x > 0): if (int(x) % 2 == 0): count += 1 x = raw_input("enter value, or q quit: ") return count
on other hand if had sequence of numbers getting number of evens o(n) , can written 1 pythonic line.
numberofevens = sum([1 if k%2==0 else 0 k in sequence])
Comments
Post a Comment