0

I am trying to recreate poker in Python and I'm trying to move cards from 2 lists, the deckNumber and deckSuit lists, into playerHand and I'm getting an "empty range for randrange() (0,0, 0)" error when using randint in line 11.

import random

deckNumber = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"]
deckSuit = ["Spades", "Diamonds", "Clubs", "Hearts"]
playerHand = []
oppHand = []

for i in range(5):
    number = deckNumber.pop(random.randint(0, len(deckNumber)-1))
    suit = deckSuit.pop(random.randint(0, len(deckSuit)-1))
    playerHand.append(number + " " + suit)

    print(playerHand)

I've tried putting another number between 0 and len(deckSuit)-1 but then it says I'm using 4 inputs instead of 3. I've also tried doing len(deckSuit)-2 and just len(deckSuit), but len(deckSuit) gives me an "out of range" error and len(deckSuit)-2 gives me the "empty range" error.

Michael M.
  • 10,486
  • 9
  • 18
  • 34
John Doe
  • 1
  • 1
  • If you include line numbers within the code, we can't copy and run it in order to help you debug the issue. – mkrieger1 Dec 27 '22 at 01:18
  • 2
    Why do you want to remove an item 5 times from `deckSuit`, which only contains 4 items? – mkrieger1 Dec 27 '22 at 01:21
  • Sorry about the line numbers, I didnt realize that would happen if I added those, wanted to make it easier to read, also mkrieger, that was the problem! thank you a lot, it was frustrating me for a couple days now and I didnt think it was such a simple fix – John Doe Dec 27 '22 at 01:43
  • Using Stack Overflow as an interactive debugger is notoriously inefficient. Instead, find and learn to use whatever [debugger](/q/25385173/90527) your development suite provides. At that point, if you encounter a problem you can't solve you can then post a question about that specific issue with a [mcve]. See "[How much research effort is expected of Stack Overflow users?](//meta.stackoverflow.com/q/261592/90527)" Please look over the [help], especially the "[ask]" article. – outis Dec 27 '22 at 09:57

0 Answers0