在python 3

时间:2018-06-28 22:26:23

标签: python python-3.x

我正在处理此代码,但是启动功能未运行。我没有收到任何错误。这是用于纸牌游戏,对吗?我正在使用python 3,并在Windows 10上通过命令提示符运行。对于我的文本编辑器,我正在使用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('')

1 个答案:

答案 0 :(得分:0)

如果没有任何错误,则需要检查工作环境。我显然会出错。

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是任何实例方法的隐式第一个参数:调用对象成为该第一个参数。只需将其命名为

    self.startup()

这将使您克服 first 结构性问题。


我强烈建议您退一步并分小段测试代码。您已经编写了50多行代码,而没有测试您的结构。在填写许多详细信息之前,请测试连接性。一次添加几行,测试每次添加。我已经修复了三个此类错误,并且仍然出现错误。