Skip to content

Instantly share code, notes, and snippets.

@Sangram92
Created February 4, 2016 10:30
Show Gist options
  • Save Sangram92/197c9db28ccd5051832b to your computer and use it in GitHub Desktop.
Save Sangram92/197c9db28ccd5051832b to your computer and use it in GitHub Desktop.
from random import randint
def cows_and_bulls():
generated_no = randint(1000,9999)
print generated_no
x = 0
count = 0
while(True):
no = input("Enter 4 digit no : ")
no_list = list(str(no))
print no
if len(str(no)) == 4:
generated_no_list = list(str(generated_no))
cows = 0
bulls = 0
for i in range(4):
if no_list[i] == generated_no_list[i]:
cows+=1
else:
bulls+=1
count += 1
print"cows: {0} and bulls: {1}".format(cows, bulls)
if no == generated_no:
print "Heyy You Win..!!! No of Guesses", count
break
else:
print"Enter 4 digit no only"
count+= 1
cows_and_bulls()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment