I have this python 3 script which should compare two lists and find equal numbers. It'a a Cows and Bulls game. Not going to go too much into details but here is the problem. When I ask for user input as a list it returns list of Strings and not integers, hence I can't compare elements with my given list if integers. Please advise how to cast userinput
list into list of digits: Script below:
import random
numtoguess = [random.randrange(0,10,1) for _ in range (4)]
print(numtoguess)
userinput = []
while numtoguess != userinput:
userinput = list(input("Welcome to Cows and Bulls game!!! \nGuess the random 4 digit number :> "))
print(userinput)
cows = 0
bulls = 0
counter = 0
for i in userinput:
if i in numtoguess and i == numtoguess[counter]:
bulls += 1
elif i in numtoguess and i != numtoguess[counter]:
cows += 1
counter += 1
print('Cows: ' + str(cows))
print('Bulls: ' + str(bulls))