奇偶数计数函数

2024-09-29 21:30:04 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是一个可以输入元组的程序,但我需要在元组中输入n个数字,并将其传递给函数以计算如何才能做到这一点?

def CountOfEvenOddOddNumbers(evodTuple):
tEvenCount = tOddCount = 0
for oetup in evodTuple:
    if(oetup % 2 == 0):
        tEvenCount = tEvenCount + 1
    else:
        tOddCount = tOddCount + 1
return tEvenCount, tOddCount

evodTuple =(12, 26, 77, 99, 66, 75, 14, 256, 19, 81, 11, 33)
print("Even and Odd Tuple Items = ", evodTuple)

evenCount, oddCount = CountOfEvenOddOddNumbers(evodTuple)
print("The Count of Even Numbers in evodTuple = ", evenCount)
print("The Count of Odd  Numbers in evodTuple = ", oddCount)

Tags: oftheincount元组evenoddprint

热门问题