MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / getClues

Function getClues

src/gamesbyexample/bagels.py:71–93  ·  view source on GitHub ↗

Returns a string with the pico, fermi, bagels clues for a guess and secret number pair.

(guess, secretNum)

Source from the content-addressed store, hash-verified

69
70
71def 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:

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected