return语句有错误..缺少1个必需的位置参数

时间:2017-04-06 16:01:34

标签: python

我想用Queue制作炸弹游戏。 但是return语句有错误,但我不知道是什么错误....这是我的代码和错误消息,请帮忙。enter image description here 我试图删除“玩家”,直到一个人离开..这个人就是这个游戏的赢家。所以我把那个人变成变量“胜利”,但它不起作用......

import random


class ArrayQueue:
    DEFAULT_CAPACITY=10

    def __init__(self):
        self._data=[None]*ArrayQueue.DEFAULT_CAPACITY
        self._size=0
        self._front=0


    def __len__(self):
        return self._size


    def is_empty(self):
        return self._size==0

    def first(self):

        if self.is_empty():
            raise Empty("Queue is empty")
        return self._data[self._front]

    def dequeue(self):
        if self.is_empty():
            raise Empty("Queue is empty")
        answer=self._data[self._front]
        self._data[self._front]=None
        self._front=(self._front+1)%len(self._data)
        self._size-=1
        return answer

    def enqueue(self, e):
        if self._size==len(self._data):
            self._resize(2*len(self.data))
        avail=(self._front+self._size)%len(self._data)
        self._data[avail]=e
        self._size+=1


    def _resize(self,cap):
        old=self._data
        self._data=[None]*cap
        walk=self._front
        for k in range(self._size):
            self._data[k]=old[walk]
            walk=(1+walk)%len(old)
        self._front=0

def hot_potato(self,players):
    pl=ArrayQueue
    for i in range(len(players)):
        pl.enqueue(players[i])
    rnum=random.randint(1,pl.__len__)

    while(True):
        bomb=pl.dequeue()
        if rnum!=0:
            pl.enqueue(bomb)
        else:
            bomb=None
            rnum=random.randint(1,p1.__len__)

        if p1.__len__==1:
            win=pl.dequeue()
            break
    return win      

players=["홍길동","홍동길","길홍동","길동홍","동홍길","동길홍","최정주","오소명","강그루"]
winner=hot_potato(players)
print(winner)

0 个答案:

没有答案