Feb-25-2018, 06:23 AM
I'm trying to learn how to have more control over increments, but I have a delema (see comments in following code):
#!/usr/bin/env python3 #PadLockGuesser.py lockCombo = 1080 #brute force pad lock guesser with while loop: guess = 0 while guess != lockCombo: #guess += 1#placing the guess incrementor here causes 0 to not be one of the guesses if guess == lockCombo: print("After " + str(guess) + " guesses, the correct combo is " + str(guess)) break else: print(str(guess) + " is not the correct combo. Trying next guess.") guess += 1#placing the guess incrementor here causes the program to stop guessing at 1079 continue #brute force pad lock guesser with for loop: guessAgain = 0 for i in range(0000,9999): if guessAgain == lockCombo: print("After " + str(guessAgain) + " guesses, the correct combo is " + str(guessAgain)) break else: print(str(guessAgain) + " is not the correct combo. Trying next guess.") guessAgain += 1The output of the for loop, however, is correct:
Output:0 is not the correct combo. Trying next guess.
1 is not the correct combo. Trying next guess.
2 is not the correct combo. Trying next guess.
3 is not the correct combo. Trying next guess.
...
1077 is not the correct combo. Trying next guess.
1078 is not the correct combo. Trying next guess.
1079 is not the correct combo. Trying next guess.
After 1080 guesses, the correct combo is 1080
How do I get the while loop to produce the same output?