Game Development Reference
In-Depth Information
digit is correct and in the correct place (the digit 6), and two digits are in the secret
number but in the wrong place (the digits 4 and 5).
Sample Run
I am thinking of a 3-digit number. Try to guess what it is.
Here are some clues:
When I say: That means:
Pico One digit is correct but in the wrong position.
Fermi One digit is correct and in the right position.
Bagels No digit is correct.
I have thought up a number. You have 10 guesses to get it.
Guess #1:
123
Fermi
Guess #2:
453
Pico
Guess #3:
425
Fermi
Guess #4:
326
Bagels
Guess #5:
489
Bagels
Guess #6:
075
Fermi Fermi
Guess #7:
015
Fermi Pico
Guess #8:
175
You got it!
Do you want to play again? (yes or no)
no
Bagel's Source Code
bagels.py
This code can be downloaded from http://inventwithpython.com/bagels.py
If you get errors after typing this code in, compare it to the topic's code with the online
diff tool at http://inventwithpython.com/diff or email the author at
al@inventwithpython.com
1. import random
2. def getSecretNum(numDigits):
3. # Returns a string that is numDigits long, made up of
Search WWH ::




Custom Search