Additional exercises
1. My code has a bug, why the door to guess passwords 11 times instead of 10 times?
A: As in vitro cycle has had a line input-12, as follows:
11 code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9)) 12 guess = raw_input("[keypad]> ") 13 guesses = 0 14 15 while guess != code and guesses < 10: 16 print("BZZZZEDDD!") 17 guesses += 1 18 guess = raw_input("[keypad]> ")
So if you do not enter only use 10 times, then you need to change the judgment conditions are as follows:
11 code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9)) 12 guess = raw_input("[keypad]> ") 13 guesses = 0 14 15 while guess != code and guesses < 9: 16 print("BZZZZEDDD!") 17 guesses += 1 18 guess = raw_input("[keypad]> ")