I’m working on #5 of games of chance in the python practice exercises, high card.
My question is that I’m trying to find the index position so that I can do a gt or lt comparison to get to the answer.
I haven’t defined my function yet, just writing up the code to see if the way I’m trying is going to work.
card_suit = ["Hearts", "Diamonds", "Spades", "Clubs"] card_size = [2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King", "Ace"] deck =  for i in card_suit: for n in card_size: tmp_deck = (str(n) + ' of ' + i) deck.append(tmp_deck) user, comp = random.choices(deck, k=2) print("Player 1 has a " + user) print("Player 2 has a " + comp) if card_size.index(user.split()) > card_size.index(comp.split()): print("Player 1 wins") elif card_size.index(user.split()) < card_size.index(comp.split()): print("Player 2 wins") else: print("Tie")
if card_size.index(user.split()) > card_size.index(comp.split()): ValueError: '8' is not in list Player 1 has a Jack of Clubs Player 2 has a 8 of Spades
My question is ‘why is the 8 not in the list’? I can print out the list and see that it’s there, yet the function is not returning it.
If I walk through the card_size line in the python shell, x = user.split() and then put it into the card_size.index(x) and I get the position of the card so I can have a gt, lt comparison.
If I do the same thing in my function I get the ValueError.
Is this a timing issue?
When looking online for an answer, stackoverflow, is basically saying that I’m pulling the “8” out of the list and that’s why it can’t be found.
I’m not removing anything from the list so I’m kind of lost.
Any help would be great.