Skip to content
Advertisement

Infinite looping Issue Python. Can’t quit game

I made a code for Blackjack in Python and whenever I run blackjack_game(deck) saying no to the ‘Play Again’ input should quit the game but it doesn’t. Funds going zero and below should also trigger the game to quit but it doesn’t.

This is what it looks like:

JavaScript

I added a quit() that should trigger should ‘while play_again == ‘Y’:’ no longer be true. This should have quit the game and stopped it from running. Instead it prompts the user again for a betting amount, acting as if I chose ‘Y’ instead.

I also tried removing:

JavaScript

and replacing this code block:

JavaScript

with this:

JavaScript

But it still wouldn’t quit and stayed as an infinite loop. Help me please, I’ve been stuck with this issue all day.

Advertisement

Answer

Can you please try by replacing from this:

JavaScript

With

JavaScript

I believe we don’t even need to add end_game as it is unnecessary in current scope.

These are nested while loop and parent while loop will not break until child breaks. so we need to add extra condition in child while loop which break it on the basis of parent check.

you can read this post 5 Ways To Break Out of Nested Loops in Python

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement