mercredi 24 mars 2021

Mastermind game: How to allow user to enter sequence length and range?

I am writing a program on the basis of guessing numbers, I would like to improve it so that the user can enter the length of the guessed sequence and the range from which the numbers are drawn. (sure with inputs) but I have no ideas how to introduce it in my application, can someone help? Here is my code:

import random


number = random.choices ([x for x in range (1, 4)], k=4)
numer_try = 0
guess = None

while number != guess:

    guess = [
        int(input("first number: ")),
        int(input("second number: ")),
        int(input("third number: ")),
        int(input("fourth number: "))
    ]

    numer_try += 1

    num_right_numbers = len([1 for i in range(4) if number[i] == guess[i]])
    print('Guessed {0} numbers.'.format(num_right_numbers))
    print('correct numbers: {0} '.format(number))

print('you won!')



Aucun commentaire:

Enregistrer un commentaire