А такой вариант более понятен? Я старался сохранить по возможности нужные части и ничего эдакого не использовать.
import random
# lets collect cows and bulls
def cowsandbools(secret, guess):
bulls = []
cows = []
for i in range(len(secret)):
digit = guess[i]
if secret[i] == digit:
bulls.append(digit)
elif digit in secret:
cows.append(digit)
return bulls, cows
print "===Lets start the game==="
secret = random.sample('0123456789', 4)
count = 1
while True:
guess = list(raw_input("Try to guess the number: "))
if len(set(guess)) != len(secret):
print "Write the number correctly"
continue
if secret == guess:
print "=========Congratulations, you win in:", count , " turns========="
print "=========Your number was:", secret, "========="
if count > 7:
print "=========I am sure you can do better========="
else:
print "==========It is a very good result=========="
break
else:
bulls, cows = cowsandbools(secret, guess)
print len(bulls), " Bulls and ", len(cows), " Cows"
count += 1