python概率計(jì)算器實(shí)例分析
本文實(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ì)有所幫助。
- Python實(shí)現(xiàn)扣除個(gè)人稅后的工資計(jì)算器示例
- 僅用50行代碼實(shí)現(xiàn)一個(gè)Python編寫的計(jì)算器的教程
- 基于python的Tkinter實(shí)現(xiàn)一個(gè)簡(jiǎn)易計(jì)算器
- Python實(shí)現(xiàn)簡(jiǎn)單的四則運(yùn)算計(jì)算器
- python正則表達(dá)式之作業(yè)計(jì)算器
- Python開發(fā)的實(shí)用計(jì)算器完整實(shí)例
- Python實(shí)現(xiàn)的科學(xué)計(jì)算器功能示例
- Python實(shí)現(xiàn)兩款計(jì)算器功能示例
- Python使用wxPython實(shí)現(xiàn)計(jì)算器
- Python Tkinter實(shí)現(xiàn)簡(jiǎn)易計(jì)算器功能
- Python實(shí)現(xiàn)的個(gè)人所得稅計(jì)算器示例
相關(guān)文章
Keras:Unet網(wǎng)絡(luò)實(shí)現(xiàn)多類語義分割方式
本文主要利用U-Net網(wǎng)絡(luò)結(jié)構(gòu)實(shí)現(xiàn)了多類的語義分割,并展示了部分測(cè)試效果,希望對(duì)你有用!2020-06-06
Python3使用requests模塊實(shí)現(xiàn)顯示下載進(jìn)度的方法詳解
這篇文章主要介紹了Python3使用requests模塊實(shí)現(xiàn)顯示下載進(jìn)度的方法,結(jié)合實(shí)例形式分析了Python3中requests模塊的配置、使用及顯示進(jìn)度條類的相關(guān)定義方法,需要的朋友可以參考下2019-02-02
python 用所有標(biāo)點(diǎn)符號(hào)分隔句子的示例
今天小編就為大家分享一篇python 用所有標(biāo)點(diǎn)符號(hào)分隔句子的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-07-07
Django中使用 Closure Table 儲(chǔ)存無限分級(jí)數(shù)據(jù)
對(duì)于數(shù)據(jù)量大的情況(比如用戶之間有邀請(qǐng)鏈,有點(diǎn)三級(jí)分銷的意思),就要用到 closure table 的結(jié)構(gòu)來進(jìn)行存儲(chǔ)。這篇文章主要介紹了Django中使用 Closure Table 儲(chǔ)存無限分級(jí)數(shù)據(jù),需要的朋友可以參考下2019-06-06
基于python的Tkinter實(shí)現(xiàn)一個(gè)簡(jiǎn)易計(jì)算器
這篇文章主要介紹了基于python的Tkinter實(shí)現(xiàn)一個(gè)簡(jiǎn)易計(jì)算器的相關(guān)資料,還為大家分享了僅用用50行Python代碼實(shí)現(xiàn)的簡(jiǎn)易計(jì)算器,感興趣的小伙伴們可以參考一下2015-12-12
Tortoise-orm信號(hào)實(shí)現(xiàn)及使用場(chǎng)景源碼詳解
這篇文章主要為大家介紹了Tortoise-orm信號(hào)實(shí)現(xiàn)及使用場(chǎng)景源碼詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03
Python設(shè)計(jì)模式之享元模式原理與用法實(shí)例分析
這篇文章主要介紹了Python設(shè)計(jì)模式之享元模式原理與用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了享元模式的相關(guān)概念、原理、定義及使用方法,需要的朋友可以參考下2019-01-01
Python安全獲取域管理員權(quán)限幾種方式操作示例
在不考慮直接攻擊域控的情況下,如何快速獲取域管理員權(quán)限呢?本文分享幾種常見的獲取域管理員權(quán)限的方式,有需要的朋友可以借鑒參考下2021-10-10
Python計(jì)算兩個(gè)日期相差天數(shù)的方法示例
這篇文章主要介紹了Python計(jì)算兩個(gè)日期相差天數(shù)的方法,結(jié)合簡(jiǎn)單實(shí)例形式分析了Python日期時(shí)間的轉(zhuǎn)換與運(yùn)算相關(guān)操作技巧,需要的朋友可以參考下2017-05-05
Python 如何實(shí)現(xiàn)文件自動(dòng)去重
這篇文章主要介紹了Python 實(shí)現(xiàn)文件自動(dòng)去重操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06

