Contact Us!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Views: 21
Image: ubuntu2004
Kernel: Python 3 (system-wide)
import numpy as np
values = ['2','3','4','5','6','7','8','9','10','J','K','Q','A'] suits = ['H','D','S','C'] cards = [[v,s] for v in values for s in suits]
def pair(): np.random.shuffle(cards) pair_counter = 0 cards_counter = 0 values = [] for card in cards: value = card[0] cards_counter +=1 if not value in values: values.append(value) if len(values) ==4: pair_counter +=1 if pair_counter == 1: return cards_counter
pair()
4

The expected amount of cards are 4 in order to get two cards with the same value.