打印时如何限制列表的内容?



如何修复输入==1:"在第19行,如果我输入"1"它的输出必须是

2 c, a - c3 c,上,5度,6 c, 7 c, 8 c, 9 c, 10摄氏度,j, Q-C, c

这是我对这个问题的试错代码

from typing import List, Any
import random
def printmenu():
    print("Menu")
    print("1. Show first 13 cards")
    print("2. Shuffle and show first 13 cards")
    print("3. Play 2 card poker")
    print("4. Stack the deck and show first 13 cards")
    print("5. Exit")
    _input: int = int(input())
    return options(_input)

def options(_input: int):
    suits = ['C', 'D', 'H', 'S']
    value = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
    deck = []
    if _input == 1:
        first13cards = []
        if(deck == []):
            for i in suits:
                for j in value:
                  print(j+"-"+i, end=",")
        elif deck != []:
            deck.clear()
            first13cards.clear()
            for i in range(52):
                deck.append(value[random.randint(0, 12)] + suits[random.randint(0, 3)])
            for i in range(13):
                first13cards.append(deck[i])
        return printmenu()
    elif _input == 2:
        for i in range(13):
            deck.append(value[random.randint(0, 12)] + suits[random.randint(0, 3)])
        print(deck)
        return printmenu()
    elif _input == 3:
        #play 2 cards poker
        return printmenu()
    elif _input == 4:
        #stack the deck & show first13 cards
        return printmenu()
    elif _input == 5:
        exit()  # exit the program
    
    for j in value:
        suit = suits[random.randint(0, 3)]
        _temp = j + suit + ""
        deck.append(_temp)
    print(deck)
    return deck

if __name__ == '__main__':
    while True:
        printmenu()
        if printmenu() == 5:
            break

这是我的试错码

对于您正在查找的字符串值,您可以这样做

deck = ",".join(map(lambda x: x + '-C', value))

,其中每个suit将与-C连接,然后连接成一个字符串,每个元素用逗号分隔。

最新更新