下面是一个可以输入元组的程序,但我需要在元组中输入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)
这将从用户获取以空格分隔的值作为输入,并将它们添加到列表中
相关问题 更多 >
编程相关推荐