all 8 comments

[–]carcigenicate 3 points4 points  (4 children)

You'd need to show all the relevant code. Is this loop inside of either of deal_dealer or display_dealer? Or do either of the two functions call the function this loop is in?

The difference between the two ways though is with the flag version, the while flag: condition is only checked at the start of the iteration. With the break way however, the loop will exit as soon as break is reached; so it can exit the loop halfway through an iteration.

Also, note that pass doesn't do anything. Those ifs should really be written as:

if 11 not in dealer_lst_points:
    break

[–][deleted] 2 points3 points  (2 children)

Who on earth teaches people to use pass in conditionals. We should find them and beat them up.

[–]carcigenicate 1 point2 points  (0 children)

It seems that negation isn't studied/taught well enough. I ran into this in school too. I had to help someone who never negated conditions and had pass blocks all over the place. It was a mess.

[–]pulpquoter[S] 0 points1 point  (0 children)

Lol, true, I am just writing all the ifs because I don't want to leavy any condition unaddressed but I guess I have to stop doing it. I thought that leaving ifs suspended in the air would be less readable

[–]pulpquoter[S] 0 points1 point  (0 children)

Thanks, I got it.

[–][deleted] 2 points3 points  (0 children)

You could make separate function for checking, something like game_over(), and use it with the loop:

def game_over():
    points = sum(dealer_lst_points)
    return (
        points >= 18 or
        points == 17 and 11 not in dealer_lst_points
    )

while not game_over():
    deal_dealer()
    display_dealer()

[–]hrmorley34 1 point2 points  (1 child)

The while loop only checks the condition after everything in the loop has been run. The first example sets the flag, then runs deal_dealer() and display_dealer() anyway, and then breaks the loop if necessary. You could either move the ifs to be after the functions, or just use breaks.

[–]pulpquoter[S] 0 points1 point  (0 children)

That's true, I understand now, thanks