感谢
修改后的代码:import random
cards = {"A":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"J":0.5,"Q":0.5,"K":0.5,"Little Joker":0.5,"Big Joker":0.5}
player = True
player_card = []
player_card_number = []
computer = True
computer_card = []
computer_card_number = []
print("目前有这些卡牌:")
for item in cards.keys():
print(item)
for i in range(5):
player_card.append(random.sample(list(cards.keys()),1))
player_card_number.append(player_card[i])
computer_card.append(random.sample(list(cards.keys()),1))
computer_card_number.append(computer_card[i])
player_number_total = player_card_number[0]+player_card_number[1]+player_card_number[2]+player_card_number[3]+player_card_number[4]
computer_number_total = computer_card_number[0]+computer_card_number[1]+computer_card_number[2]+computer_card_number[3]+computer_card_number[4]
print("玩家的牌是:",player_card)
print("玩家总共有",str(player_number_total),"点")
print("电脑的牌是:",computer_card)
print("电脑总共有",str(computer_number_total),"点")
if player_number_total > 10.5:
print("你被淘汰了哟")
player = False
else:
pass
if computer_number_total > 10.5:
print("电脑被淘汰了")
computer = False
else:
pass
if player == True and computer == True:
print("你们还可以继续游戏")
if player_number_total != 10.5 and computer_number_total != 10.5:
player_ask_number = int(input("你想要再抽几张牌?(1~4)"))
computer_ask_number = random.randint(1,4)
for i in range(player_ask_number):
player_card.append(random.sample(list(cards.keys()),1))
player_card_number.append(player_card[i+5])
for i in range(computer_ask_number):
computer_card.append(random.sample(list(cards.keys()),1))
computer_card_number.append(computer_card[i+5])
player_number_len = len(player_card_number)
computer_number_len = len(computer_card_number)
player_number_total = player_card_number[0]+player_card_number[1]+player_card_number[2]+player_card_number[3]+player_card_number[4]+player_card_number[5]+player_card_number[player_number_len]
computer_number_total = computer_card_number[0]+computer_card_number[1]+computer_card_number[2]+computer_card_number[3]+computer_card_number[4]+computer_card_number[5]+computer_card_number[computer_number_len]
if player_number_total > 10.5 and computer_number_total > 10.5:
print("都没有赢哟,再来一局吧")
elif player_number_total <= 10.5 and computer_number_total > 10.5:
print("哈,你赢了,祝贺")
elif player_number_total > 10.5 and computer_number_total <= 10.5:
print("电脑赢了,继续加油")
else:
if player_number_total > computer_number_total:
print("哈,你赢了,祝贺")
elif player_number_total < computer_number_total:
print("电脑赢了,继续加油")
else:
print("平局哟,再来一局吧")
elif player_number_total == 10.5 and computer_number_total != 10.5:
print("哈,你赢了,祝贺")
elif player_number_total != 10.5 and computer_number_total == 10.5:
print("电脑赢了,继续加油")
else:
print("都没有赢哟,再来一局吧")
elif player == True and computer == False:
print("哈,你赢了,祝贺")
elif player == False and computer == True:
print("电脑赢了,继续加油")
else:
print("都没有赢哟,再来一局吧")
|