I am beginner in Python. Can anyone help me with the Cows and Bulls game.? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

29th Jul 2019, 2:36 PM
Divyanshu Raj Karan
Divyanshu Raj Karan - avatar
1 Answer
+ 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)
29th Jul 2019, 3:15 PM
Steven M
Steven M - avatar