最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python概率計(jì)算器實(shí)例分析

 更新時(shí)間:2015年03月25日 10:25:26   作者:令狐不聰  
這篇文章主要介紹了python概率計(jì)算器實(shí)現(xiàn)方法,實(shí)例分析了Python實(shí)現(xiàn)概率計(jì)算的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了python概率計(jì)算器實(shí)現(xiàn)方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

from random import randrange
#randrange form random module
def calc_prob(strengths):
  """A function that receives an array of two numbers 
  indicating the strength of each party 
  and returns the winner"""
  if strengths[1]>strengths[0]:
#Bring the bigger number to the first position in the array
    temp=strengths[0]
    strengths[0]=strengths[1]
    strengths[1]=temp   
  prob1=abs(strengths[0]-strengths[1])
#The relative strength of the 2 parties
  prob2=randrange(0,100)
#To calculate the luck that decides the outcome
  if prob2 in range(0,33-prob1):
#Check if the weaker party is capable of winning. 
#The condition gets narrower with the increase
#in relative strengths of each parties
    return strengths[1]
  elif prob2 in range(33-prob1,66-prob1):
  #The middle condition
    return "Draw"
  else:
     return strengths[0]
#Luck favors the stronger party and if relative strength
#between the teams is too large, 
#the match ends up in favor of the stronger party 
#Example
calc_prob([50,75]);#Always has to be a list to allow exchange
#Can be programmed in hundreds of better ways. Good luck!

希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

开封市| 布尔津县| 涟水县| 武隆县| 珠海市| 兴化市| 客服| 新和县| 修水县| 武山县| 安溪县| 鹤壁市| 德江县| 英吉沙县| 隆德县| 偃师市| 泽普县| 山阴县| 汨罗市| 洱源县| 惠东县| 中卫市| 芦山县| 安阳市| 肃宁县| 达日县| 建水县| 兴国县| 容城县| 惠州市| 新竹县| 来宾市| 德安县| 文昌市| 墨竹工卡县| 招远市| 宁海县| 惠东县| 万州区| 罗定市| 湛江市|