Advertisement
Pnerd6

Consecutive Cards

May 9th, 2022 (edited)
983
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. from random import shuffle
  2.  
  3. values = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K']
  4. cards = 4 * values  # create 52 cards (only the 52 values are required; suits are irrelevant and not needed)
  5. trials = 5_000_000
  6. desired_outcome = 0
  7.  
  8. for _ in range (trials):
  9.     shuffle(cards)  # shuffle the cards using random.shuffle()
  10.     for i in range (51):
  11.         if cards[i] == cards[i+1]:
  12.             desired_outcome += 1
  13.             break
  14.  
  15. print(f'Desired Outcome = {desired_outcome :,} times = {desired_outcome*100/trials :.2f}%')
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement