Reshuffle the deck after each draw. Calculate the odds that 10,000 random draws will result in a flush. I made it more complicated by accumulating how many times each of the four suits appeared separately
import random list=["2","3","4",'5','6','7','8','9','10',"J","Q","K","A"] list2=["H","C","D","S"] list3=[] n=0 a=0 while a<4: n=0 while n<13: list3+=[list[n]+list2[a]] n+=1 a+=1 i=0 r=0 d=0 c=0 s=0 h=0 while i <10000: (list3) list4=list3[0:5] i+=1 for card in list4: if 'D' in card: d+=1 if d==5: r+=1 for card in list4: if 'H' in card: h+=1 if h==5: r+=1 for card in list4: if 'S' in card: s+=1 if s==5: r+=1 for card in list4: if 'C' in card: c+=1 if c==5: r+=1 d=0 c=0 s=0 h=0 print ('Number of natural Flushes:',r) print('Percentage:',r/100,'%')
Results:
There is the issue of running the code to save the path, if it is a beginner, I suggest that the default path can be, my is C:\python27, because later used to Django when ate a loss.
summarize
The above is the entire content of this article on Python3 simple example of calculating the probability of the same flower code, I hope it will help you. Interested friends can continue to refer to this site:
Python implementation of string matching algorithm code examples
Python language to describe maximal continuous subsequences and
Python Programming Implementation of Dichotomy and Newton's Iterative Method for Square Root Code
If there are deficiencies, welcome to leave a message to point out. Thank you friends for the support of this site!