0

What I am trying to do is create a while loop that always begins by gathering input. However, whenever I run it and input "hit", it seems to skip the prompt and go directly to the conditional statements under "if hit".

while current_score <= 21:
    hit = input("Do you want to hit or stay? ") 
    if hit == 'stay' or ' Stay':
        print("The dealer's hand:", dealer_hand)
        if(current_score < dcurrent_score):
            print("you have lost")
            break
        if(current_score > dcurrent_score):
            print("you have won")
            break

    if hit == 'hit' or 'Hit':
        z = randint(0, 51)
        card_three = deck[z]
        while card_three == card_two or card_three == card_one:
            z = randint(0, 51)
            card_three = deck[z]
            current_hand.append(card_three)
        if current_score > 21:
            print("you have lost")
            break
  • Can you clarify? Show us the input/output sequence when you run it and why it’s wrong. – Arya McCarthy Apr 28 '20 at 18:08
  • 1
    Does this answer your question? [How to test multiple variables against a value?](https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-against-a-value) – G. Anderson Apr 28 '20 at 18:09
  • `if hit == 'stay' or ' Stay'` will always equate to `True` because you're missing another comparison after the `or`. – Hampus Larsson Apr 28 '20 at 18:09

2 Answers2

1

You have a problem in this line:

if hit == 'stay' or 'Stay':

and this one

if hit == 'hit' or 'Hit':

'Stay' and 'Hit' are truthy values so condition always pass. Change them to

if hit == 'stay' or hit == 'Stay':

and

if hit == 'hit' or hit == 'Hit':

Or more pythonic way:

if hit.lower() == 'stay':

'lower' method fill make string lowercase

schumskie
  • 157
  • 1
  • 7
0

I believe your problem would be solved if you type:

if (hit=="stay" or hit=="Stay"):
   <statements>
if (hit=="hit" or hit=="Hit"):
   <statements>

I suggest you go through the following article:

  1. https://www.geeksforgeeks.org/basic-operators-python/
  2. https://realpython.com/python-or-operator/
TennisTechBoy
  • 101
  • 10