import randomcard =[]for i in range(3,16):if i == 11:i ='J'elif i == 12:i = 'Q'elif i == 13:i = 'k'elif i == 14:i = 'A'elif i == 15:i = '2'card.append('♠' + str(i))card.append('♣' + str(i))card.append('♥' + str(i))card.append('♦' + str(i))card.append('小王')card.append('大王')dict_card=dict([(i,card.index(i)) for i in card ])random.shuffle(card)player1=[]player2=[]landlord=[]i = 0while(i<51):player1.append(card[i])player2.append(card[i+1])landlord.append(card[i+2])i+=3end_card =card[51:54]landlord+=end_carddef putCard(card,dict_card):card = sorted(card, key=lambda x: dict_card.get(x), reverse=True)return cardresult = putCard(player1,dict_card)result1=putCard(player2,dict_card)result2=putCard(landlord,dict_card)print(result)print(result1)print(result2)
如果觉得《利用python语言编写小游戏斗地主》对你有帮助,请点赞、收藏,并留下你的观点哦!