简体   繁体   English

如何更改此代码的输出以仅输出前 2 张卡片?

[英]How do I change the output of this code to only output the first 2 cards?

import itertools
import random

vals = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
suits = [
        u"\u2665",  # Hearts
        u"\u2666",  # Diamonds
        u"\u2663",  # Clubs
        u"\u2660",  # Spades
        ]

deck = list(itertools.product(vals, suits))

random.shuffle(deck)

for val, suit in deck:
    print('%s%s' % (val, suit))
import itertools
import random

vals = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
suits = [
        u"\u2665",  # Hearts
        u"\u2666",  # Diamonds
        u"\u2663",  # Clubs
        u"\u2660",  # Spades
        ]

deck = list(itertools.product(vals, suits))

random.shuffle(deck)

for val, suit in deck[:2]:
    print('%s%s' % (val, suit))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获得仅打印一个输出的代码? - How do I get my code to only print one output? 如何让这个 Python 代码只输出一行? - How do I get this Python code to output only one line? 如何仅打印最后一个 output? - How do I print the last output only? 如何更改 VSCode 中的输出文件? - How do I change the output file in VSCode? 如何通过python代码仅打印输出的前几行? - How to print only first few lines of output through python code? 我如何使此python代码输出0 1 4 6 - How do I make this python code output 0 1 4 6 如何将第一个操作的输出发送到第二个操作的输入? - How do I send the output of my first operation into the input of the second? 如何在非列表输出中返回第一个链接 - How do I return the first link in a non-list output 如何使用 python 网络抓取从列表中提取每个输入的 html 文本输出作为列表。 我已经编写了代码,但只给出了第一个条目的输出 - How to extract html text output as list for each input from list using python web scraping. I have written code, but gives only first entry output 迁移学习 - 如何仅更改 TensorFlow 中的 output 层? - Transfer Learning - How can I change only the output layer in TensorFlow?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM