首页 > 其他 > 详细

预测球队比赛成绩

时间:2020-06-09 11:47:13      阅读:38      评论:0      收藏:0      [点我收藏+]

(一)代码

题目:

c.羽毛球比赛规则( (学号尾号为7,8,9同学必做及格题) )
1.21分制,3局2胜为佳
2.每球得分制
3.回合中,取胜的一方加1分
4.当双方均为20分时,领先对方2分的一方赢得该局比赛
5.当双方均为29分时,先取得30分的一方赢得该局比赛
6.一局比赛的获胜方在下一局率先发球

 1 # -*- coding: utf-8 -*-
 2 """
 3 Created on Tue Jun  9 11:18:48 2020
 4 
 5 @author: 13549
 6 """
 7 
 8 from random import random
 9 #第一阶段
10 def printIntro():
11     print("模拟两个选手A和B的羽毛球比赛")
12     print("程序运行需要A和B的能力值(以0到1之间的小数表示)")
13 def getInputs():
14     a = eval(input("请输入选手A的能力值(0-1): "))
15     b = eval(input("请输入选手B的能力值(0-1): "))
16     n = eval(input("模拟比赛的场次: "))
17     return a, b, n
18 def simNGames(n, probA, probB):
19     winsA, winsB = 0, 0
20     for i in range(n):    #将模拟n场比赛分解为n次模拟一场比赛
21         scoreA, scoreB = simOneGame(probA, probB)
22         if scoreA > scoreB:
23             winsA += 1
24         else:
25             winsB += 1
26     return winsA, winsB
27 def printSummary(winsA, winsB):
28     n = winsA + winsB
29     print("羽毛球比赛分析开始,共模拟{}场比赛".format(n))
30     print("选手A获胜{}场比赛,占比{:0.1%}".format(winsA, winsA/n))
31     0.8
32     print("选手B获胜{}场比赛,占比{:0.1%}".format(winsB, winsB/n))
33 def main():
34     printIntro()
35     probA, probB, n = getInputs()
36     winsA, winsB = simNGames(n, probA, probB)
37     printSummary(winsA, winsB)
38 #第二阶段    
39 def simOneGame(probA, probB):
40     scoreA, scoreB = 0, 0
41     serving = "A"
42     while not gameOver(scoreA, scoreB):
43         if serving == "A":
44             if random() < probA:
45                 scoreA += 1
46             else:
47                 serving="B"
48         else:
49             if random() < probB:
50                 scoreB += 1
51             else:
52                 serving="A"
53     return scoreA, scoreB
54 #第三阶段
55 def gameOver(a,b):
56     if (a>=20 and b>=20):
57         if(abs(a-b)==2 and a<=29 and b<=29):
58             return True
59 
60         else:
61             return a==30 or b==30
62     else:
63         return False
64 
65 main()
66 
67 print("学号尾数为9")

技术分享图片

 

 技术分享图片

 

 (二)使用pyinstaller打包

1,安装,pip install PyInstaller

2,常用打包方式

单一文件,pyinstaller -F -i icoName.ico filename.py

非单一文件,pyinstaller -D -i icoName.ico filename.py

3,外部文件的引用,如果涉及外部文件的使用,建议以非单一文件形式打包,一方面可以增加使用的弹性,另一方面更好的管理与使用,避免单一文件过大。

如果外部文件较少,可以直接手动拷贝文件到相应目录

预测球队比赛成绩

原文:https://www.cnblogs.com/qinan-nlx/p/13071540.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!