Write a program that will simulate the process of dealing cards from a 52-card deck by generating 1,000 random integers in the range 1–52. Assume that numbers 1–13 represent clubs, 14–26 represent diamonds, 27–39 represent hearts, and 40–52 represent spades. Display the number of times each suit occurred in the 1,000 “deals.”
Answers
Answer
Required to do :
- Generate 1,000 random integers in the range 1 - 52
- Display the number of times each suit occurred in the 1,000 deals.
Constraints :
- 1,000 random integers
- 1-13 clubs
- 14-26 diamonds
- 27-39 hearts
- 40-52 spades
Program :
from random import *
list_of_random_vals = []
for i in range(0,1000):
random_val = rañdint(1,52)
list_of_random_vals.append(random_val)
hearts = 0
clúbs = 0
spades = 0
diamonds = 0
for item in list_of_random_vals:
if 1 <= item <= 13:
clúbs +=1
elif 14 <= item <= 26:
diamonds +=1
elif 27 <= item <= 39:
hearts +=1
else:
spades +=1
suits = {"clúbs " : clúbs, "diamonds " : diamonds, "hearts " : hearts , "spades " : spades }
print("No. of times each suit occured in 1000 deals = ")
print(suits)
Explanation :
Here we are asked to generate random values in the range 1 - 52 .
For this we need to use random module which has a useful method called rañdint(x,y) which helps us to generate a random values in the required range ...
rañdint(self, x,y)
x,y is the range in which you want to generate the random value.
Moreover, we need to generate 1000 values for this we need to implement the above steps repeatedly for 10³ times inorder to avoid that we will use a for loop here which will repeat this task for 10³ times.
At last we will use the basic concepts of list , if , elif and dictionary to obtain required results .
Output :-
Refer the attachment !!
Note :
some character are written in different font like for eg : letter u in clubs is written as ú . So, before implementing the program make sure you edit them first and then run ..