Count Even Numbers User has Inputted PYTHON 3

前端 未结 5 1185
死守一世寂寞
死守一世寂寞 2021-01-24 03:11

I must create two functions. One that can tell whether one number is odd or even by returning t/f, and the other will call the first function then return how many even numbers t

5条回答
  •  醉话见心
    2021-01-24 03:39

    Here is another approach:

    def is_even(number):
        return number % 2 == 0
    
    def even_count(numbers_list):
        count = 0
    
        for number in numbers_list:
            if is_even(number): count += 1
    
        return count
    
    raw_numbers = input("Please enter more than one number: ")
    numbers_list = [int(i) for i in raw_numbers.split()]
    
    count = even_count(numbers_list)
    print(count)
    

    This will take care of all other numbers too.

提交回复
热议问题