Game Development Reference
In-Depth Information
11 - Bagels
unique random digits.
4. numbers = list(range(10))
5. random.shuffle(numbers)
6. secretNum = ''
7. for i in range(numDigits):
8. secretNum += str(numbers[i])
9. return secretNum
10.
11. def getClues(guess, secretNum):
12. # Returns a string with the pico, fermi, bagels clues
to the user.
13. if guess == secretNum:
14. return 'You got it!'
15.
16. clue = []
17.
18. for i in range(len(guess)):
19. if guess[i] == secretNum[i]:
20. clue.append('Fermi')
21. elif guess[i] in secretNum:
22. clue.append('Pico')
23. if len(clue) == 0:
24. return 'Bagels'
25.
26. clue.sort()
27. return ' '.join(clue)
28.
29. def isOnlyDigits(num):
30. # Returns True if num is a string made up only of
digits. Otherwise returns False.
31. if num == '':
32. return False
33.
34. for i in num:
35. if i not in '0 1 2 3 4 5 6 7 8 9'.split():
36. return False
37.
38. return True
39.
40. def playAgain():
41. # This function returns True if the player wants to
play again, otherwise it returns False.
42. print('Do you want to play again? (yes or no)')
43. return input().lower().startswith('y')
44.
45. NUMDIGITS = 3
46. MAXGUESS = 10
47.
48. print('I am thinking of a %s-digit number. Try to guess
what it is.' % (NUMDIGITS))
49. print('Here are some clues:')
50. print('When I say: That means:')
51. print(' Pico One digit is correct but in the
wrong position.')
Search WWH ::




Custom Search