Count Even Numbers User has Inputted PYTHON 3

前端 未结 5 1193
死守一世寂寞
死守一世寂寞 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:51

    So by calling CountEvent(d) outside the scope of the function CountEven, you aren't using recursion, you're simple calling the function after it's been defined.

    Try reducing the amount of code outside of your functions.

        #Start by declaring your functions:
        def isEven(n):
            return n % 2 == 0
    
        def countEven():
            count = 0
            string_of_numbers = input("Please enter numbers separated by spaces: ")
            list_of_number_characters = string_of_numbers.split(' ')
            for number in list_of_number_characters:
                number_as_int = int(number)
                if isEven(number_as_int) == True:
                    count = count + 1
            print("There were " + str(count) + " even numbers found.")
    
    
        countEven() #Call the function that runs your program
    

提交回复
热议问题