# guessing game from 102 to 987 # users are supposed to enter a 3 digit number that doesn't have any repeating numbers (hence, starting from 102 to 987) # it should print ball: x when there is x numbers of digits the users guessed that is equal but in the wrong placement to the digit of the actual number # it should print strike: x when there is x numbers of digits the users guessed that is equal and in the right placement to the digit of the actual number from random import randint while True: count = 0 setnum = randint(102, 987) y = [int(i) for i in str(setnum)] # while each digit is not a repeat # e.g. 123 or 693, not 122 or 343 while (y[0] != y[1] and y[0] != y[2] and y[1] != y[2]): ball = 0 strike = 0 guess = int(input("Guess your number: ")) x = [int(i) for i in str(guess)] # counts how many balls/strikes the user have if len(x) == 3: if guess != setnum: count += 1 if x[0] == y[0]: strike += 1 if x[1] == y[1]: strike += 1 if x[2] == y[2]: strike += 1 if x[0] == y[1]: ball += 1 if x[0] == y[2]: ball += 1 if x[1] == y[0]: ball += 1 if x[1] == y[2]: ball += 1 if x[2] == y[0]: ball += 1 if x[2] == y[1]: ball += 1 print(strike, " Strike") print(ball, " Ball") else: print("CONGRATS") print("You got it in", count, "tries.\n") break else: print("Please print a three digit number.\n") continue else: continue