我正在编写这段代码,但是启动函数没有运行。我没有收到任何错误。这是用来打牌的,帮帮忙?我使用的是python 3,在windows10上通过命令提示符运行,我的文本编辑器使用的是Atom。
import random
print("Sam's Casino")
class Game:
def __init__(self):
self.cards = ['1','2','3','4','5','6','7','8','9','10','J',
'Q','K','1','2','3','4','5','6','7','8','9','10','J',
'Q','K','1','2','3','4','5','6','7','8','9','10','J',
'Q','K','1','2','3','4','5','6','7','8','9','10','J',
'Q','K']
self.hand1 = []
self.hand2 = []
self.center = []
self.pile1 = []
self.pile2 = []
self.points1 = 0
self.points2 = 0
input('__init__ completed - ')
self.startup(self)
def deal(self):
self.count = 0
for card in self.cards:
if self.count < 4:
self.hand1.append(card)
self.count += 1
elif self.count > 3 and self.count < 8:
self.hand2.append(card)
self.count += 1
print('hi')
input('deal test - ')
def startup(self):
input('startup __init__ test:')
print("Sam's Casino Version 1.1")
random(self.cards)
print(self.cards)
self.deal(self)
print(self.hand1)
print(self.hand2)
input('self.startup completed - ')
def trick(self):
self.points1_add = input('Points1_add? - ')
self.points2_add = input('Points2_add? - ')
self.points1 += self.points1_add
self.points2 += self.pointd2_add
input('trick test1 - ')
def turn(self):
startup(self)
while self.points1 < 21 and self.points2 < 21:
print('turn test - ')
trick(self)
Key = input('Game()_run? - ')
if Key == 'y':
Game().run()
elif Key == 'n':
print('closing')
input('ctest')
else:
print('invalid input')
input('')
发布于 2018-06-29 06:34:05
如果你没有得到任何错误,那么你需要检查你的工作环境。很明显我得到了一个错误。
Traceback (most recent call last):
File "so.py", line 60, in <module>
Game().run()
File "so.py", line 20, in __init__
self.startup(self)
TypeError: startup() takes 1 positional argument but 2 were given
这个调用是多余的:
self.startup(self)
self
是任何实例方法的隐式第一个参数: call对象成为第一个参数。简单地将其称为
self.startup()
这将帮助您克服第一个结构问题。
我强烈建议你回过头来测试你的代码。你已经写了超过50行的代码,而没有测试你的结构。在你填写这么多细节之前,先测试一下你的连接性。一次添加几行代码,测试每个添加的代码。我现在已经修复了三个这样的错误,但仍然收到错误。
https://stackoverflow.com/questions/51091968
复制相似问题