我想计算输入中的偶数/奇数的数量但是当我为它制作公式时它会给我一个错误: 在我的情况下,它必须在代码中有一个循环和迭代,所以不能显着改变任何东西。
exceptions.TypeError: not all arguments converted during string formatting
代码:
count_odd = None
count_even = None
while True:
numbers = raw_input("Enter a number: ")
if numbers == "done": break
try:
num = int(numbers)
except ValueError:
print "Not a number"
continue
for x in numbers:
if x % 2: #error is here
count_even+=1
else:
count_odd+=1
print("Number of even numbers :",count_even)
print("Number of odd numbers :",count_odd)