0

I am making blackjack for a small project and I have the basics set up but I have encountered an issue. the game runs off of while Phand!=21 it will ask the user to hit fold or stand. when it hits its fine as it repeats and adds a a card and folding is fine too as it ends the program but using stand and getting out of the loop is my issue.

while Phand!=21 and Pchoice!="stand": was my first attempted solution but the problem with checking for the word stand is that the variable Pchoice is after the while stament like this:

while Phand!=21:
    Pchoice = (input("Would you like to hit stand or fold"))

That's why I cannot put the stand in the while as it comes second.

secondly, I tried using break; which did work but had the side effect of only allowing the user to give one input which makes them unable to draw more than one card so while it is a quick fix it is not ideal.

if anyone has any idea of how I can exit the while statement when the player chooses stand that would be greatly appreciated

Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48

1 Answers1

0
Phand = 10
Pchoice = None
while Phand!=21 and Pchoice != 'stand':
    Pchoice = (input("Would you like to hit stand or fold"))


# or

while Phand!=21:
    Pchoice = (input("Would you like to hit stand or fold"))
    if Pchoice == 'stand':
        break
ykhrustalev
  • 604
  • 10
  • 18