This script will run as expected and pass doctests without any errors in Python 2.6:
def num_even_digits(n):
"""
>>> num_even_digits(123456)
3
>>> num_even_digits(2468)
4
>>> num_even_digits(1357)
0
>>> num_even_digits(2)
1
>>> num_even_digits(20)
2
"""
count = 0
while n:
digit=n%10
if digit%2==0:
count+=1
n/=10
else:
n/=10
return count
if __name__ == '__main__':
import doctest
doctest.testmod()
In Python3.0 this is the output:
**********************************************************************
File "/home/calder/My Documents/Programming/Python Scripts/ch06.py", line 3, in
__main__.num_even_digits`
Failed example:
num_even_digits(123456)
Expected:
3
Got:
1
**********************************************************************
File "/home/calder/My Documents/Programming/Python Scripts/ch06.py", line 5, in
__main__.num_even_digits
Failed example:
num_even_digits(2468)
Expected:
4
Got:
1
**********************************************************************
1 items had failures:
2 of 5 in __main__.num_even_digits
***Test Failed*** 2 failures.
I have tried running the Python script "2to3", but no changes are needed it says. Does anyone know why the script will not run in Python 3?