function - 将一个函数的值分配给另一个函数
问题描述
我希望 get_suit(hand) 函数将正确的手分配给 display_hand 函数中的打印函数。它所做的只是为手中的两张牌分配一套花色。
输出应为: Player's hand is 19 :[('Q', 'of', 'Diamonds'), ('8', 'of', 'Spades')
我认为问题可能出在 get_suits 函数中。
hand = ['QD', '8S']
def get_hand_total(hand):
total = 0
for card in hand:
card_value = card[0]
if card_value in 'KQJT':
total += 10
elif card_value == 'A':
total += 11
else:
total += int(card_value)
return total
def get_suits(hand):
suit = ''
for card in hand:
card_suit = card[1]
if card_suit == 'S':
suit = 'Spades'
elif card_suit == 'C':
suit = 'Clubs'
elif card_suit == 'D':
suit = 'Diamonds'
else:
suit = 'Hearts'
return suit
def display_hand(hand_text, hand):
final_hand = []
for card in (hand):
get_suits(hand)
get_hand_total(hand)
hand_list = card[0], 'of', get_suits(hand)
final_hand.append(hand_list)
print(hand_text, get_hand_total(hand), ':', final_hand)
解决方案
推荐阅读
- sql - 将星期几名称转换为星期几编号 Vertica
- python - 为什么我的图像加载到数据集中都是白色的?
- google-apps-script - 通过 Google Apps 脚本获取每张幻灯片的 lh3.googleusercontent.com 链接
- c - 测试 FPE 和陷阱 FPE 有什么区别?
- java - Spring Webclient decode custom application/multipart-related,application/dicom (Wado-RS)
- c++ - c++中模板类的重载运算符ostream不起作用
- php - ->toArray() 给出空数组而不是对象
- c# - 移除 android 启动器图标周围的白色容器
- bash - 用一个换行符替换两个换行符,用两个换行符替换两个以上的换行符
- reactjs - React-如何获取 blob SAS URL 或 SAS 令牌?