Answer:
Written in Python
import random
#randnum = str(random.randint(999, 9999))
tryagain = "Yes"
while tryagain == "Yes":
randnum = "1234"
trys = 1
guess = input("Guess: ")
count = 0
while not count == 4:
for i in range(0,4):
if randnum[i] == guess[i]:
count = count + 1
if not count == 4:
print("You match "+str(count))
guess = input("Guess: ")
trys = trys + 1
else:
print("Congratulations, you match at "+str(trys))
trys = 1
tryagain = input("Start? (Yes/No): ")
Explanation:
I've added the full source code as an attachment where I used comments as explanation