我编码一个基本的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'是一个不同的变量。 –
方式**太多'全球'**。 –