So, here is the code. Below you find the live video making of the code, all improvised and rough.
from random import random from random import randint from random import randrange def rnd(): guess = [] for i in range(3): n = randrange(1, 10) guess.append(n) return guess a = rnd() a = [str(x) for x in a] a = "".join(a) score = 10 for t in range(10): print("\nTry n." + str(t+1)) print("=======") print("What were the numbers?") answer = input("> ") if answer == a: print("\n***********\n") print("Good, you guessed") print("Your score is " + str(score)) break else: count = 0 pos = 0 for n, i in enumerate(a): if a[n] == answer[n]: count += 1 elif a[n] in answer: pos += 1 print("_______") print(str(count) + " numbers right") print(str(pos) + " numbers" + " are not in the right position") score -= 1 print("The solution was:" + a) print("Your last try was:" + answer)
This is the output of a game
Try n.1 ======= What were the numbers? > 123 _______ 0 numbers right 1 numbers are not in the right position Try n.2 ======= What were the numbers? > 245 _______ 1 numbers right 1 numbers are not in the right position Try n.3 ======= What were the numbers? > 267 _______ 1 numbers right 0 numbers are not in the right position Try n.4 ======= What were the numbers? > 264 _______ 2 numbers right 0 numbers are not in the right position Try n.5 ======= What were the numbers? > 274 _______ 2 numbers right 0 numbers are not in the right position Try n.6 ======= What were the numbers? > 284 _______ 2 numbers right 0 numbers are not in the right position Try n.7 ======= What were the numbers? > 294 *********** Good, you guessed Your score is 4 The solution was:294 Your last try was:294 >>>
The video
Twitter: @pythonprogrammi - python_pygame