程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python3 calculates the probability of the same flower

編輯:Python

Shuffle the cards after each draw . Calculation 10000 The probability of the same flower can be obtained by random sampling . What I did was complicated , Four designs have been accumulated and appeared several times .

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:
random.shuffle(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,'%') 

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved