0
I am beginner in Python. Can anyone help me with the Cows and Bulls game.?
Cows and bulls game: Generate random four digit number. Compare the random number with user input. If position on indexes same in both print cows else bulls. Random_number = 1234 User_input = 1537 Output 2 Cows 0 bulls And if user_input = 1432 Output = 2 Cows 2 bulls
1 ответ
+ 2
Something like this:
from random import randint
n=0
x=int(input("give me a number"))
y=randint(1000, 10000)
cows=0
bulls=0
for each in str(x):
if each==str(y)[n]:
cows+=1
n+=1
else:
bulls+=1
n+=1
print(y)
print(bulls)
print(cows)