mercredi 15 octobre 2014

How to enter a list into a function? in python


Vote count:

-1




Write a function called “find_even_count” which allows the user to enter an arbitrary sequence of positive integers at the keyboard, and then prints the number of positive even integers user enters. The sequence of numbers is unknown at the beginning. User may enter negative number to show the end of the sequence. For example: If user enters the sequence, 1, 3, 5, 23, 56, 14, 68, 25, 12, -1 then your function needs to print “4 even numbers”, since there are 4 even numbers in the sequence. Hint: Use while loop


here is my code


find_even_count(x): i = x even_count = 0 while x> 0: if i%2 ==0: even_count+=1



print even_count


i keep getting the error code


Traceback (most recent call last): File "", line 1, in find_even_count(2,22,224,24,-1) File "/Users/rayhow/Desktop/assignment2_Q4.py", line 5, in find_even_count if i%2 ==0: TypeError: unsupported operand type(s) for %: 'tuple' and 'int'


please help mee haha



asked 1 min ago







How to enter a list into a function? in python

Aucun commentaire:

Enregistrer un commentaire