【发布时间】:2022-12-17 17:52:08
【问题描述】:
我正在尝试使用 OOP 在 python 中编写纸牌游戏。 用户应选择红色(红心和钻石) 或黑色(梅花和黑桃) 然后用户继续游戏。
这是代码:
class game:
def __init__(self, player, score):
self.player = player
self.score = score
def start_game(self, player, score, team):
self.score = score
self.player = player
self.team = team
print("Welcome")
player = input("Please enter your name: ")
print('While you start your score is 1000')
team = input((' RED or BLACK \n Your team : '))
while team == 'red':
print('Great, You have chosen Team Red, hearts and diamonds will fetch you points, clubs and sp')
print("")
playGame = input(('Press ENTER to play'))
print('game starts')
shuffleCard = input(('Press ENTER to shuffle and Pick your card'))
deck = Deck()
deck.shuffle()
print(' that was a good mix')
showCard = input(('Press ENTER to reveal your card'))
player = player()
player.draw(deck)
player.showHand
break
终端给出了这个错误:
Traceback (most recent call last):
File "/Users/yoshithkotla/PycharmProjects/pythonFinalProject001/main.py", line 71, in <module>
player = player()
TypeError: 'str' object is not callable
【问题讨论】:
-
player是一个字符串对象。