hank3r - 1 month ago 16

Python Question

I have 2 int variables

1 contains a user input, the other is a computer generated number(0,99)

How can i check if the input variable contains an digit in computer generated number i.e. if the user enters 45 and the computers guess was 54, if user guesses one of the digits correctly i.e. user guesses 23 and computer guess was 35.

`Guess = int(input("Please guess a number between 0 to 99:"))`

if Guess <= 99 and Guess >= 0:

break

except ValueError:

print("")

RandomNum = random.randint(0,99)

print("Random Generated Number",RandomNum)

if RandomNum == Guess:

print("Jackpot!! You win 100 !")

if RandomNum == Guess[0,1]:

print("Right Digits,wrong order. You win 10")

Answer

It appears that you want to check if the user's number contains the same digit as the computer-generated numbers.

If you only ever going to have two digits numbers you can get away with `if str(RandomNum) == str(Guess)[::-1]:`

. This will check if the string value of `RandomNum`

is equal to the string value of `Guess`

in reverse.

If you want a more generalized solution then first you will need to define the desired behavior.