0

Yesterday I posted a question regarding a NameError I am getting when running my program. From the comments I got on my post I decided to ask the same question, only this time adding a link to my Github repository so you could get a complete reference and context to my specific problem, hopefully helping me understand what I should do to solve my problem. This is my Github repository:

https://github.com/AlonSalzmann/Blackjack

the problem I'm having is getting this error:

Traceback (most recent call last):
  File "C:/Users/pc/PycharmProjects/Blackjack/Game Flow/Game_Flow.py", line 83, in <module>
    player_turn()
  File "C:/Users/pc/PycharmProjects/Blackjack/Game Flow/Game_Flow.py", line 29, in player_turn
    user_decision = input('would you like to hit or hold?')
  File "<string>", line 1, in <module>
NameError: name 'hit' is not defined

While running this block of code:

def player_turn():
    if sum(player_card_numbers) < 21:
        user_decision = input('would you like to hit or hold?')
        if user_decision == 'hit':
            player_cards.append(deck.draw())
            print player_cards, dealer_cards
            player_turn()

        elif user_decision == 'hold':
            print "Dealer's turn!"
            dealer_turn()
        else:
            print "player must choose 'hit' or 'hold'"
            player_turn()

    elif sum(player_card_numbers) == 21:
        print "Blackjack!"
        dealer_turn()

    else:
        print "Player Burnt! \nDealer's turn!"
        dealer_turn()

This block of code is located in "Gameflow.py" in the "Gameflow" folder. Once again i would really appreciate an explanation, hopefully made easier now that the entire project is accessible with my Github account. This project is written in python 2.7

martineau
  • 119,623
  • 25
  • 170
  • 301
alon salzmann
  • 141
  • 1
  • 1
  • 6
  • Please reformat the code in your question, Python needs proper indentation. Show the complete traceback and mark the last mentioned line (where error occurs) with a comment in your code. – Michael Butscher Jan 15 '19 at 13:05
  • 2
    Possible duplicate of [input() error - NameError: name '...' is not defined](https://stackoverflow.com/questions/21122540/input-error-nameerror-name-is-not-defined) – DWuest Jan 15 '19 at 13:09
  • 1
    The code in your repository looks like it for a package. How is the above code being executed—where's the code `inport`ing `Gameflow`? Regardless, I think @DWuest answer is correct. – martineau Jan 15 '19 at 14:05

1 Answers1

1

When using Python 2.x, you have to utilize the raw_input function, not the input function.

In Python 2.x, input() evaluates the input as a Python expression, not a string.

You can learn more about that behaviour here.

DWuest
  • 619
  • 1
  • 7
  • 18