mardi 5 février 2019

how to check if the printed value of a random.choice matches with a "guess" variable

Basically, I'm writing a basic "hello world" code to refresh my memory and I'm stuck. I want to print a random choice from the list "numbers" and I want to check to see if my initial x matches with the output that was randomly chosen. However, when I run the code all I'm getting is print("nice") even when the numbers don't match. Here is the code:

import random

numbers = [1, 2, 3, 4, 5, 6]
x = int(input("Enter your guess: "))

def random_choice(numbers):
    if x in numbers:
        print(random.choice(numbers))
        if numbers.count(x):
            print("nice")
        else:
            print("not nice")


random_choice(numbers)




Aucun commentaire:

Enregistrer un commentaire