Returns a string with the pico, fermi, bagels clues for a guess and secret number pair.
(guess, secretNum)
| 69 | |
| 70 | |
| 71 | def getClues(guess, secretNum): |
| 72 | """Returns a string with the pico, fermi, bagels clues for a guess |
| 73 | and secret number pair.""" |
| 74 | if guess == secretNum: |
| 75 | return 'You got it!' |
| 76 | |
| 77 | clues = [] |
| 78 | |
| 79 | for i in range(len(guess)): |
| 80 | if guess[i] == secretNum[i]: |
| 81 | # A correct digit is in the correct place. |
| 82 | clues.append('Fermi') |
| 83 | elif guess[i] in secretNum: |
| 84 | # A correct digit is in the incorrect place. |
| 85 | clues.append('Pico') |
| 86 | if len(clues) == 0: |
| 87 | return 'Bagels' # There are no correct digits at all. |
| 88 | else: |
| 89 | # Sort the clues into alphabetical order so their original order |
| 90 | # doesn't give information away. |
| 91 | clues.sort() |
| 92 | # Make a single string from the list of string clues. |
| 93 | return ' '.join(clues) |
| 94 | |
| 95 | |
| 96 | # If the program is run (instead of imported), run the game: |