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
3
  • Can you clarify? Show us the input/output sequence when you run it and why it’s wrong. Commented Apr 28, 2020 at 18:08
  • 1
    Does this answer your question? How to test multiple variables against a value? Commented Apr 28, 2020 at 18:09
  • if hit == 'stay' or ' Stay' will always equate to True because you're missing another comparison after the or. Commented Apr 28, 2020 at 18:09

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.