rlvaugh / Impractical_Python_Projects

Code & supporting files for chapters in book
408 stars 270 forks source link

Chapter 7: Project 14: Listing 7-10 (Second Printing) #7

Closed alexpovel closed 4 years ago

alexpovel commented 5 years ago

In the line prefaced by bullet-point number 7, it reads:

next_try[lock_wheel] = randint(0, len(combo) - 1)

which means that we try a digit on that index that depends on the combination length, instead of just picking a digit from 0 to 9. It works in the example, since the combination is 10 digits long, so that the line evaluates to randint(0, 10 - 1). However, it fails to solve all combinations where

any([digit > len(combo) - 1 for digit in combo])

holds true, e.g. an 8 occurs in a combination of length 5.

While writing this, I noticed the issue is fixed here.

I am leaving this issue for others to find and as a reminder that this should be corrected in future print versions.

rlvaugh commented 4 years ago

Thanks. The project was written for a 10-digit combo, but just before going to print the editor suggested making it work for any combo. I forgot to update this line. It will be corrected in the 3rd edition.

Please check out the webpage for other errata: https://nostarch.com/impracticalpythonprojects.