I have just started learning python 2.7.1, and I have written a code for a Cows and Bulls game, in which you need to guess a four digit number by continuously re-entering 4 digits till you get the right number. But for some reason by code just lasts for 3 loops max. Here is the code:-
number=raw_input("Enter the 4 digit number to be guessed:")
a=map(int,str(number))
def Guess():
yournumber=raw_input("Enter your number now:")
b=map(int,str(yournumber))
i=j=k=0
while i<=3:
if a[i]==b[i]:
j+=1
elif b[i] in a:
k+=1
i+=1
print str(j),"Bulls and "+str(k),"Cows"
return yournumber
Guess()
c=Guess()
if c==number:
print "BINGO! You have guessed the number!"
else:
Guess()
Aucun commentaire:
Enregistrer un commentaire