0

Cows and Bulls Python - program error

In this programm the user can give a 4 digit number as a guess for the generated number. When a digit is guessed right at the correct place, you get a cow, if it's in the generated number but at the wrong place, you get a bull. Current Problem: TypeError: Can't convert 'int' object to str implicitly [ from random import randint def getnumber(): a1 = str(randint(0, 9)) b1 = str(randint(0, 9)) c1 = str(randint(0, 9)) d1 = str(randint(0, 9)) return a1, b1, c1, d1 def game(): a, b, c, d = getnumber() number = a + b + c + d print ("Welcome to the Cows and Bulls Game! \n") guess = input("Enter a number: ") bulls, cows = 0, 0 while guess != number: z = 0 for x in guess: if x in guess: if guess.index(x) == number.index(z): cows += 1 else: bulls += 1 z += 1 print("{0} cows, {1} bulls".format(str(cows), str(bulls))) bulls = 0 cows = 0 guess == input("") if guess == number: print("This is the right number!") if __name__ == "__main__" : game() ]

30th Jun 2018, 10:30 AM
proxophy
proxophy - avatar
1 Odpowiedź
+ 6
You get an indentation error because you have to indent the last line as follows: if __name__ == '__main__' : game()
30th Jun 2018, 10:32 AM
DAB
DAB - avatar