lundi 19 octobre 2020

Check if userinput matches any digits of a (random) integer

random = random.randint(1000, 9999)
guess = int(input("Enter your guess: "))
while guess != random:
    guess = int(input("That was incorrect! Enter your guess: "))

This works as a very simple guessing game, however I would like to include something where after every unsuccessful try it would say how many numbers out of the four digit number were correct.

I have not attempted this, mainly because I'm not sure how this could be done.

e.g

random = 1234
Enter your guess: 1111
You guessed 1 number correct
Enter your guess: 1222
You guessed 2 numbers correct
...... and so on



Aucun commentaire:

Enregistrer un commentaire