• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python概率计算器实例分析

python概率计算器实例分析

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python 概率,python 概率图,python 概率分布图,python 概率密度函数,python开发实例等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了python概率计算器实现方法。分享给大家供大家参考。具体实现方法如下:

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!
</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • 一步步解析Python斗牛游戏的概率
  • python概率计算器实例分析

相关文章

  • 在Python 3中实现类型检查器的简单方法
  • Python3实现并发检验代理池地址的方法
  • Python制作爬虫采集小说
  • python中map、any、all函数用法分析
  • 简单介绍Python的Tornado框架中的协程异步实现原理
  • Python实现把json格式转换成文本或sql文件
  • 使用PYTHON创建XML文档
  • Python操作MySQL数据库9个实用实例
  • Python计算字符宽度的方法
  • 简单的Apache+FastCGI+Django配置指南

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • python冒泡排序简单实现方法
    • 浅析python递归函数和河内塔问题
    • TensorFlow——Checkpoint为模型添加检查点的实例
    • python 打印出所有的对象/模块的属性(实例代码)
    • python实现计算倒数的方法
    • Python编程入门的一些基本知识
    • Python实现CET查分的方法
    • 浅谈Python数据类型之间的转换
    • 详解python并发获取snmp信息及性能测试
    • Python获取系统默认字符编码的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有