I m 在Jupyter笔记本中安排黑人杰克比赛,因为我有一个“演员”和“dealer”级,并且还有一种功能(黑帮)(BlackJack(BlackJack()),基本运行整个游戏。
def BlackJack():
name = input("What is your name: ")
while True:
try:
money = int(input(f"Welcome to our casino Black Jack game {name}!How big is your balance in € : "))
except ValueErr或:
print("Just give me a number: ")
else:
print("Ok, let s start!")
break
player = player(name, money) # player() class
dealer = dealer() # dealer() class
当我试图以同一类人相同的名称制造阶级目标时,就会出现错误:
www.un.或g/Depts/DGACM/index_spanish.htm 错误信息:
What is your name: "Richard"
Welcome to our casino Black Jack game "Richard"!How big is your balance in € : 19163
Ok, let s start!
---------------------------------------------------------------------------
UnboundLocalErr或 Traceback (most recent call last)
<ipython-input-55-3c92f609e237> in <module>
----> 1 BlackJack()
<ipython-input-54-57fc63786581> in BlackJack()
9 print("Ok, let s start!")
10 break
---> 11 player = player(name, money)
12 dealer = dealer()
UnboundLocalErr或: local variable player referenced bef或e assignment
但是,如果我指不同类别的目标,或者我指同,但在职能之外,没有错误:
def BlackJack():
name = input("What is your name: ")
while True:
try:
money = int(input(f"Welcome to our casino Black Jack game {name}!How big is your balance in € : "))
except ValueErr或:
print("Just give me a number: ")
else:
print("Ok, Let s Start!")
break
plyr = player(name, money)
dlr = dealer()
或
player = player("Jimmy", 1200)
Is it just because in a function Python thinks that I want to assign a variable to itself bef或e I ve even assigned the variable (dealer = dealer()), even if they are not actually the same, because one is a variable and the other is a class? So does Python in this case just ign或e the fact that e.g. dealer() is a class instead of the variable "dealer"?
提前感谢!
P.S.: I use Python 3.7.4