python概率计算器实例分析
文章主要介绍了python概率计算器实现方法,实例分析了Python实现概率计算的`技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了python概率计算器实现方法。分享给大家供大家参考。具体实现方法如下:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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!
希望本文所述对大家的Python程序设计有所帮助。
-
万恶的function在javascript中的运用实例分析
javascript中最有特色而又让你困惑的function算一个了下面看一下常用操作复制代码代码如下:functiondoit(){.....}doit();javascript中的函数我们可以把它当作方法使用复制代码代码如下:varobj=newObject();=function(){.....}();而function实际上就是对象(即F...
-
浅谈jquery 注意事项与常用语法
1、关于选择器中含有特殊符号选择器中含有".","#","(","]"等特殊字符,根据W3C的规定,属性值中是不能含有这些特殊字符的,例如:复制代码代码如下:bb如果按照普通的方式来获取,例如:复制代码代码如下:$("#id#b");$("#id[1]");以上代码不能正确获取到元素,正确的写法如下:复...
-
javascript操作select元素案例分析
本文实例讲述了javascript操作select元素的.用法。分享给大家供大家参考。具体分析如下:这里熟悉一下js对select元素的操作,html页面中建立一个form,其中包含一个select元素和submit按钮。当选择select中某一项时改变其文字,当select中所有项的文字都改变后,重新恢...
-
css经典教程
css经典教程1有些习惯显得尤为重要,今天与您分享六个CSS习惯。因为习惯其实是会变的,所以只能写“最近”的。这些习惯都跟技术无关,如果不遵守,也不会出错。但是我觉得良好的习惯会体现一个人的素质。我们在中向大家介绍过很多CSS经验与技巧,这些东西都发布在/css/...
相关文章
- PEP六年级上册《Unit1Howdoyougotoschool》知识点归纳
- 新概念英语青少版2a课文Unit 04:The top three persent
- 分析Python中下划线的使用方法
- The truth about money and happiness高中英语作文
- PEP六上Unit2 Ways to go to school教学反思
- How To Control The Population英语作文
- 英语满分作文:On the Way to School
- 2017计算机一级基础和Photoshop考试大纲考点题型分析
- php表单提交与$-POST实例分析
- Photoshop正片叠底的计算分析