我編碼一個基本的BlackJack遊戲,我挑戰自己,使盡可能多的功能成爲可能,從而使代碼如下所示:Python; NameError:名字「handsum」沒有定義
funcA()
funcB()
funcC()
至於反對:
funcA()
print("this")
print("that")
funcB()
這裏是我的問題是在我的代碼:
def playerTurn():
global handSum
global cardOne
global cardTwo
global dealerSum
global upCard
global downCard
global bet
global newCard
global dealerNewCard
str(handsum)
str(cardOne)
str(cardTwo)
str(upCard)
str(money)
print("You are lying at", handSum, "with a", cardOne, 'and a', cardTwo
+ '.', "The Dealer has a", upCard, "facing up. You have $" + money + '.')
int(handsum)
int(cardOne)
str(cardTwo)
str(upCard)
str(money)
sleep(1.3)
bet=int(input('How much would you like to bet? '))
sleep(1.3)
money-=bet
print("Your bet is $%s." %bet)
sleep(2.5)
playerInput=input(str(print('''Would you like to:
Hit (H)
Stand (S)
Double (D)
Stick (SP)
Enter Letter for Answer: '''))).upper
sleep(1)
while True:
Hit()
Stick()
Double()
Quit()
而這裏的錯誤,我得到一次我的代碼達到這樣的功能:
Traceback (most recent call last):
File "C:\Users\Owner\Desktop\Python\Games\Python 3.X\BlackJack\BlackJack.py",
line 20, in <module>
Start()
File "C:\Users\Owner\Desktop\Python\Games\Python 3.X\BlackJack\BlackJack.py",
line 16, in Start
Intro()
File "C:\Users\Owner\Desktop\Python\Games\Python
3.X\BlackJack\PlayerTurns.py", line 242, in Intro
playerTurn()
File "C:\Users\Owner\Desktop\Python\Games\Python
3.X\BlackJack\PlayerTurns.py", line 188, in playerTurn
str(handsum)
NameError: name 'handsum' is not defined
我對這個遊戲使用了多個python文件(2)。
它看起來不像,但一切正常縮進。 –
'handsum'和'handSum'是一個不同的變量。 –
方式**太多'全球'**。 –