mardi 31 août 2021

How to check if a specific input integer is in a random sample of a list [closed]

I'm sure that i'm doing something wrong, but i'm still learning. Basicly i want to check if my input is equal to random list of digits.

from random import sample

combo = int(input("Please enter a random combination of digits: (without 0)\n"))
tries = int(input("How many tries do you give me: ?\n"))
combo_lenght = len(str(combo))
print(combo_lenght)
print(type(combo_lenght))
print(f"I don't know the combination, but the lenght is {combo_lenght} digits.")
list_number = list(range(1, combo_lenght + 1))
list_input = int(combo)

for i in range(tries):
    var = (sample(list_number, len(list_number)))
    if list_input in var:
        print(f"Well, done! {var}")
        print(var)
    else:
        print(f'I keep trying to guess it... {var} ')
        print(combo)



Aucun commentaire:

Enregistrer un commentaire