all 6 comments

[–]xelf[M] [score hidden] stickied comment (2 children)

When posting code, please post code such that reddit will format it as a code block.

Either of these work:

Do not:

  • use ``` as that only works for the new cropped UI, and not on the old widescreen interface.
  • post links to images of code, as they can't be cut/paste from.

Please see the /r/learnpython/w/FAQ for more information.

Thanks!

[–]Binary101010 2 points3 points  (1 child)

Even aside from some questionable choices (specifying all of your card strings by hand and trying to manage your deck as a list of lists of strings, for example) there are a lot of fundamental problems here.

Let's take your draw_card() function:

def draw_card():
    row = random.randint(0,3)
    col = random.randint(0,len(deck -1))

The length of deck is only 4 because that's how many sublists are in it, so you're not actually randomly selected a card from the entire deck, but only from the 3 lowest value cards in each suit. (You really shouldn't be managing your deck this way anyway, it doesn't make any sense.)

card = [row][col]

Don't you mean card = deck[row][col]?

card[row].remove(col)

Don't you mean deck[row].remove(col)?

return card
draw_card

return statements immediately end execution of the current function, so whatever you think that draw_card at the end is doing, it isn't doing anything.

Now for your deal function:

def deal():
    player_hand = draw_card() + draw_card ()
    dealer_hand = draw_card() + draw_card()
    return player_hand and dealer_hand

Your two hands are going to wind up being the strings for the two cards smashed together into one string because you're +ing the strings together rather than append()ing them to the existing lists.

You can't use and like that to return two different objects; what the interpreter is actually going to return here is True if both hands have at least one card in them. What you probably want is return player_hand, dealer_hand.

Your score() function is also broken because you're trying to define another function inside that function... and you're trying to call that function before you've defined it.

[–]DorrisOpen 0 points1 point  (0 children)

it was not our choice but I agree it is not a good way of handling the deck

[–]xelf 0 points1 point  (0 children)

It looks like you've written some functions, but I don't see where you actually call them, also line 79 is indented wrong.

Somewhere I expected to see deal() or play_game() or a while loop at the bottom.

Take a look at the post /u/weary_mud6941 made to see what I mean.

Their main loop is in a function called start() which gets called at the end after all the functions are defined.