# Why in my implementation of the game "Bulls and cows" does not count cows?

``````import random
game_array1 = [n for n in range (1000, 10000)]
game_array2 = []
BullsCounter = 0
CowsCounter = 0
rndm = str(random.choice(game_array1))
print(rndm)
BullsCows=str(input())
for element in game_array1:
for x in range(4):
if str(game_array1[element-1000])[x] == rndm[x]:
BullsCounter += 1
for y in range(4):
if (str(game_array1[element-1000])[x] == rndm[y] and x!=y) :
CowsCounter += 1
if BullsCounter == int(BullsCows[0]) and CowsCounter == int(BullsCows[1]):
game_array2.append(game_array1[element-1000])
BullsCounter = 0
CowsCounter = 0
print(game_array2)``````

I'm busy as a puzzle game. Called bulls and cows. The user of the program thinks of any 4значное number, and the program has to guess. How? Now tell. The first output of the program - I have this number rndm - can be any number from the array. The user must enter 2значное number, the first digit of which is the number of complete matches the correct number with rndm - that is, the same numbers are in the same place, and the second number is the number of partial matches, that is, the numbers are the same, but the infection at different locations are. If there are such coincidences, such as rndm = __9_, and we made _99_ of "bull" - 3 digit numbers, the second in the span.
So what I'm saying. I have written a piece of code for some reason decided to forget that there are cows, and displays only matches for the bulls.
NOTE. Now I made only the first pass through the array elements 1000 10000.., you know, cycle through afterward. Could You write the problem code?
March 19th 20 at 09:06
March 19th 20 at 09:08
This task can be solved easier. First, prompt the user for the number 1000, then 2000, etc. up to 9000 and depending on the response to either leave the figure as is or changed to 100, 10, 1 ie. move figure left to right on the number while the number may not fall into place. And so with each number.
For example, the user said that the 9000 figure 9 in its place, then invite 9100, etc.
Thanks for a new idea, but my goal is to have the program guess the number in minimum number of times - when I proposed code will be appended, need only 3-4 times - genevieve_Schinner17 commented on March 19th 20 at 09:11
March 19th 20 at 09:10
We are about two and about four numbers , so interesting
cm in the book Roman Suzi "Python script" at the end there, the game code is quite good,
although the old Python, I students for many years gave her, and together, collectively
played with the computer, and every time the score is not better than 1:4 in his favor, although all
the group discussed each move....
Will read, thank you - genevieve_Schinner17 commented on March 19th 20 at 09:13
March 19th 20 at 09:12

Find more questions by tags Python