Ask coding questions

← Back to all posts
I am extremely confused

So I have recently started trying python again, and im already confused. At line 77 of my "maybe blackjack" program, it asks if they would like to [1], hit, or [2], stay, but for some reason whenever the person chooses either option, the code just completely skips if for seemingly no reason, even though theirs an if statement, doesn't even throw an error, just skips both if statements, im sorry for the lack of information but I am super confused as to whats happening here. (sometimes after the hit or stay it throws an error about getting the sum of dealer_hand, ill fix that eventually, dont worry about it)


In order to properly diagnose this issue, I've found that if a section of code is completely skipping, there's a problem with if statements. Looking at lines 91->95, you're checking if the hit_stay2 is an integer when hit_stay2 is always going to be a string. This is because you never converted it from a string (on input) to an integer. This would be fixed by changing hit_stay2 = input("Would you like another card?\n[1] Hit\n[2] Stay") to hit_stay2 = int(input("Would you like another card?\n[1] Hit\n[2] Stay"))

Next issue is that you're using if on if hit_stay2 == 2 rather than elif. Now you may ask, "why's that an issue?". Well it's mostly for semantic purposes. If hit_stay isn't == 1, then if hit_stay == 2, if not then just continue. That's about as far as I can see it. It's not a necessary change although, but it does help with readability and consistency.

Another thing, why are you using a loop condition rather than break? That would allow for an instantaneous exit of the loop rather than having to complete the rest of the code. It would help tremendously with being able to trace the flow of the program.

Anyway that's my 2 cents. Hope it helps.


@SamuelPKuld oh my god samuel 😩


@whywhywhy It's okay it's okay


It seems like the input on line 77 is a string, whereas you are trying to evaluate it in your IF statements as an integer. Try changing line 77 to this:

Alternatively, you could change your IF statements to look like this: