Created
February 4, 2016 10:30
-
-
Save Sangram92/197c9db28ccd5051832b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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