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

Function main

barebones/bagels-barebones.py:5–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import random
4
5def main():
6 print('Bagels (barebones version), a deductive logic game.')
7 print('By Al Sweigart al@inventwithpython.com')
8 print()
9 print('When I say: That means:')
10 print(' Pico One digit is correct but in the wrong place.')
11 print(' Fermi One digit is correct and in the right place.')
12 print(' Bagels No digit is correct.')
13 print()
14 print('For example, if the number is 248 and you guess 843')
15 print('the clues would be Fermi Pico.')
16
17 # Make the secret number the player needs to guess:
18 numbers = list('0123456789') # Create a list of digits 0 to 9.
19 random.shuffle(numbers) # Shuffle them into random order.
20
21 # Get the first 3 digits in the list for the secret number:
22 secretNum = str(numbers[0]) + str(numbers[1]) + str(numbers[2])
23
24 print('I have thought up a 3-digit number.')
25 print('You have 10 guesses to get it.')
26
27 numGuesses = 1
28 while numGuesses <= 10:
29 print('Guess #', numGuesses)
30 guess = input('> ')
31
32 clues = getClues(guess, secretNum)
33 print(clues)
34 numGuesses += 1
35
36 if guess == secretNum:
37 break # They're correct, so break out of this loop.
38 if numGuesses > 10:
39 print('You ran out of guesses.')
40 print('The answer was', secretNum)
41
42 print('Thanks for playing!')
43
44
45def getClues(guess, secretNum):

Callers 1

Calls 1

getCluesFunction · 0.70

Tested by

no test coverage detected