0
I’m trying to intersect the player list with the computer list, but I’m getting an error that says "line 13, in print(set(player).intersection(computer)) Typeerror: 'int' Object is not iterable".
Would anyone know where I’m going wrong?
from random import sample
lista = []
for numero in range(1,4):
jogador = int(input(f'{numero}º número: '))
lista.insert(numero, jogador)
print(lista)
jogo = list(range(1, 21))
computador = sample(jogo, 3)
print(computador)
print(set(jogador).intersection(computador))
The two variables will be only an integer value and not a set, so there is no way to calculate the intersection between them. What exactly do you need to do? You do nothing with the variable
lista
?– Woss
As both will receive 3 values I thought this would be a set. I wanted to know the intersection of the 3 values given by the user with the 3 values that the computer will choose. I used the list to create the player variable list.
– Alineat
Are you sure it should be
set(jogador)
and notset(lista)
?– Woss
Wow, that’s right, thank you so much.
– Alineat