I am working on a Bulls and cows game.
And I have the following code that calculated the number of bulls and cows:
let User and comp be the lists that have the 3 digits that the user entered and the number randomly generated by the comp
cows = 0 bulls = 0 for x in User: if x in comp: if comp.index(x) == User.index(x): bulls += 1 else: cows += 1
This works completely fine, unless the number generated by the computer has repeated digit(like 277) and I enter 447. then what happens is that I get 1 cow and zero bulls. Whereas I should get 1 bull and 0 cows.
Note that there is no issue with the game when there are no repeated digits.
I am unable to get what the problem is and why it is occurring. I would greatly appreciate any kind of help in understanding the root of this problem.
more importantly I want to get this done with. So I want a clarification on this approach or I want a new way to think about this.
I am using Python Tkinter to program this game.
please help me with this issue.