June 2017
Beginner
352 pages
8h 39m
English
What we want to do now is watch execution and see why we never exit this function's loop. Let's use next to move to the first line of the loop body:
(Pdb) next> /Users/sixty_north/examples/palindrome.py(9)digits()-> while x != 0:(Pdb) next> /Users/sixty_north/examples/palindrome.py(10)digits()-> div, mod = divmod(x, 10)(Pdb)
Now lets look at the values of some of our variables and try to decide what we expect to happen. We can examine values by using the print command:
(Pdb) print(digs)[](Pdb) print x1234
This looks correct. The digs list — which will contain the sequence of digits in the end — is empty, and x is what we passed in. We expect the divmod() function to return 123 and 4, so let's try that:
(Pdb) next ...
Read now
Unlock full access