From 44ce1c387964d7e1aa7dac5aefdb00b9f14006c9 Mon Sep 17 00:00:00 2001 From: Daniel <59575049+lemoentjiez@users.noreply.github.com> Date: Sun, 11 Dec 2022 18:09:55 +0200 Subject: [PATCH] Update mastermind.py --- LabMD_2/mastermind.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/LabMD_2/mastermind.py b/LabMD_2/mastermind.py index 8b13789..f97d868 100644 --- a/LabMD_2/mastermind.py +++ b/LabMD_2/mastermind.py @@ -1 +1,36 @@ +import random + +num = random.randrange(1000, 10000) +n = int(input("Guess the number: XXXX")) +if (n == num): + print("You won! You're a Mastermind!") +else: + ctr = 0 + while (n != num): + ctr += 1 + count = 0 + n = str(n) + num = str(num) + correct = ['X']*4 + for i in range(0, 4): + if (n[i] == num[i]): + count += 1 + correct[i] = n[i] + else: + continue + if (count < 4) and (count != 0): + print("Not really. But you guessed ", + count, " digit(s) correct!") + print("These digits are correct: ") + for k in correct: + print(k, end=' ') + print('\n') + print('\n') + n = int(input("Enter next numbers: ")) + elif (count == 0): + print("All digits are wrong.") + n = int(input("Enter next numbers: ")) + if n == num: + print("You became a Mastermind!") + print("It took ", ctr, "tries.")