Originally Posted by Scorpions4ever
It seems you want to generate a list of numbers from 1..9 or some such finite quantity and make sure that each number only occurs once.
In that case, it is faster to simply take a unique list of numbers and randomly shuffle it. This guarantees that the numbers are unique and will not be repeated. You can use random.shuffle() to shuffle a list.
Then simply iterate through the array and pick each element of the list as your random number.
I've used random.sample like you suggested. The problem now is when I go to compare my random number to a user input, it won't work. I assume this is because you can't compare int's and strings? What can I do to fix this?
Code:
num = random.sample(range(1,9), 4)
print(num)
playagain = "y"
player = input("Enter your name: ")
while playagain == "y":
guess = input("Enter your guess: ")
while len(guess) != size:
print("Invalid try again")
guess = input("Enter your guess: ")
if guess == num:
print("Congratulations, you guessed it correctly")