从一个列表中删除一个项目并将其存储到另一个列表的末尾

时间:2018-05-09 20:50:33

标签: python list

你好我在python中制作一个简单的纸牌游戏,其中玩家比较一张牌的统计数据,具有较高stat值的牌赢得该回合而输家给他们那张牌,将其从牌组中移除并将其放入获胜者套牌的结束。

这是我的游戏代码,包括一轮游戏:

import random
   class Ram():
        def __init__(self, name, weight, milk, wool, offs, thigh, fert, meat, fat):
           self.name = name
           self.weight = weight
           self.milk = milk
           self.wool = wool
           self.offs = offs
           self.thigh = thigh
           self.fert = fert
           self.meat = meat
           self.fat = fat

       def __repr__(self):
           return f"{self.name,self.weight,self.milk,self.wool,self.offs,self.thigh,self.fert,self.meat,self.fat}"


def Read(txtfile):
    datalist=[]
    f = open(txtfile, "r", encoding="utf-8")
    for line in f:
        datalist.append(line.split(','))
    f.close()
    cardlist = []
    for i in datalist:
        cardlist.append(Ram(i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]))
    return cardlist

def RandomChoice():
   l=["User","Computer"]
   return random.choice(l)

 cardlist=Read("hrutaspil.txt")

 random.shuffle(cardlist)
 split = len(cardlist) // 2

user_deck = cardlist[:split]
computer_deck = cardlist[split:]


game=input("Do you want to play?(y/n)")
if game == "y":
    if RandomChoice() == "User":
       print("The user chooses first")
       print("Your top card is:",user_deck[0].name)
       print("1 = weight =",user_deck[0].weight)
       print("2 = milk =", user_deck[0].milk)
       print("3 = wool =", user_deck[0].wool)
       print("4 = offs =", user_deck[0].offs)
       print("5 = thigh =", user_deck[0].thigh)
       print("6 = fert =", user_deck[0].fert)
       print("7 = meat =", user_deck[0].meat)
       print("8 = fat =", user_deck[0].fat)
       choice=input("Choose stat: ")
       if choice == ("1"):
          print("Weight is:",float(user_deck[0].weight))
          print("compared with computer:",float(computer_deck[0].weight))
          if float(computer_deck[0].weight) > float(user_deck[0].weight):
             print("Computer wins.")
          else:
             print("You win.")

现在,我如何从输家牌组中取出一张牌并将其添加到获奖者牌组的底部?

1 个答案:

答案 0 :(得分:0)

pd.cut

您是否也意识到用户赢得了联系?基于阅读你的问题,我不确定你的意图。