Skip to content

Instantly share code, notes, and snippets.

@jampola
Created September 8, 2016 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jampola/cfd200542a08e4ac5685598587b217eb to your computer and use it in GitHub Desktop.
Save jampola/cfd200542a08e4ac5685598587b217eb to your computer and use it in GitHub Desktop.
from random import randint, randrange
number = [randrange(1,9) for x in range(4)]
guesscount = 1
def game(guess):
cows = 0
bulls = 0
global guesscount
if guess != ''.join(str(x) for x in number):
guesscount+=1
for x in range(len(number)):
if int(guess[x]) in number:
if int(guess[x]) == number[x]:
cows+=1
else:
bulls+=1
print("{} cows, {} bull").format(cows,bulls)
else:
print("You got it! It took you %s guesses") % guesscount
exit()
def main():
while True:
myguess = raw_input("Guess: ")
game(myguess)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment