这是我的代码和错误,搞不懂为什么会有这种错误,希望能帮我解答
2条回答 默认 最新
- 梦里逆天 2022-09-01 22:23关注
你输的那个冒号好像是中文的,第40行,多了个等号
from random import random def printIntro(): print('模拟选手A、B比赛') print('A、B的能力值以0和1之间的小数表示') def getInputs(): a = eval(input('A选手的能力者(0-1):')) b = eval(input('B选手的能力者(0-1):')) n = eval(input('比赛场次:')) return a, b, n def printSummary(winsA, winsB): n = winsA + winsB print(f'分析开始,共模拟{n}场比赛') # print(f'选手A胜{winsA}场,胜率{(winsA / n) * 100}%') # print(f'选手B胜{winsB}场,胜率{(winsB / n) * 100}%') print('选手A胜{}场,胜率{:0.1%}'.format(winsA, winsA / n)) print('选手B胜{}场,胜率{:0.1%}'.format(winsB, winsB / n)) def gameOver(a, b): return a == 15 or b == 15 def simOneGame(probA, probB): scoreA, scoreB = 0, 0 serving = 'A' while not gameOver(scoreA, scoreB): if serving == 'A': if random() < probA: scoreA += 1 else: serving = 'B' else: if random() < probB: scoreB += 1 else: serving = 'A' return scoreA, scoreB def simNGames(n, probA, probB): winsA, winsB = 0, 0 for i in range(n): scoreA, scoreB = simOneGame(probA, probB) if scoreA > scoreB: winsA += 1 else: winsB += 1 return winsA, winsB def main(): printIntro() probA, probB, n = getInputs() winsA, winsB = simNGames(n, probA, probB) printSummary(winsA, winsB) main()
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用
悬赏问题
- ¥15 基于卷积神经网络的声纹识别
- ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
- ¥100 为什么这个恒流源电路不能恒流?
- ¥15 有偿求跨组件数据流路径图
- ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
- ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
- ¥15 CSAPPattacklab
- ¥15 一直显示正在等待HID—ISP
- ¥15 Python turtle 画图
- ¥15 stm32开发clion时遇到的编译问题